Another name for Ad-hoc is "not Infrastructure Mode", so if you look at some of the example service code that I have here, you'll see a private method that looks like this:
private bool ConnectToNetwork(
string ssid,
string passphrase,
bool adhoc,
AuthenticationMode mode,
WEPStatus encryption)
{
// other setup code, etc
return m_wzc.AddPreferredNetwork(ssid,
!adhoc,
passphrase,
1,
mode,
encryption,
eap);
}
Notice how it's passing the bool parameter for infrastructure mode as the second parameter. You simply need to add another public method that calls into ConnectToNetwork that sets this to true (every method in the service right now passes false because I didn't have Ad-hoc as a requirement when I wrote the code).