4

In Windows Mobile, when you open Internet Explorer and type in a URL that your device can't connect to, you are notified of this and prompted to (manually) navigate to the screen where you can actually do something about this as a user (Network Management), like so:

alt text http://www.freeimagehosting.net/uploads/d3d95e00d2.gif

However, if a .NET Compact Framework application tries to connect to a webservice and the webservice URL is not reachable, the "Cannot Connect" bubble does not appear, and instead the call to the webservice just fails. Sometimes we end up talking customers through this process on the phone:

alt text http://www.freeimagehosting.net/uploads/e74a0d4230.gif

and then they still have another 2 steps to go.

Question 1: Is it possible to programmatically control (in C#) what the two ComboBoxes on the Network Management screen are set to?

Usually fixing a customer's connectivity problems involves fiddling with these two boxes until they can connect. The problem is that because customers can freely alter their network stuff here themselves, I often don't know what to tell them to set it to ("it says what?" is something I say a lot). From my searches so far, it looks like DMProcessConfigXML is the way this would be done, but all I know so far is that you call this method and pass it some XML.

Question 2: Is it possible to programmatically (C#) trigger the "Cannot Connect" bubble, or better yet is it possible to programmatically make the Network Management screen appear immediately?

Presumably, if my code can't see the webservice URL it could trigger the bubble or go directly to the screen.

MusiGenesis
  • 74,184
  • 40
  • 190
  • 334

2 Answers2

3

In answer to your question 2, this code will show the connections control panel:

Process.Start(@"\windows\ctlpnl.exe", "cplmain.cpl,19");

A lot of the built in settings applets are shown through ctlpnl.exe. I got the magic number from the list here, not sure if it'll help, because you still need to guide the user through the rest of the comms setup.

With respect to your question 1, I have used DMProcessConfigXML and also config manager setup cabs to configure the comms settings (admittedly from c++, but looking at the api it should be straightforward to p/invoke as Shane has suggested). It was a while ago so I don't have any examples to hand right now, but we definitely got it to make new network settings and switch those drop downs to select the new settings. I'll see if I can dig up an example of the XML later.

It seems there is no need for P/Invoke, ConfigurationManager.ProcessConfiguration is the managed wrapper in the Microsoft.WindowsMobile namespace that calls DMProcessConfigXML.

I'm still looking for the right xml to send to it, most likely some combination of CM_Networks, CM_Planner and maybe some others... details are all here but the documentation is a little tricky to work out what does what, and I can't remember as it was a long time ago :(

Ok, after a little experimenting (as I didn't find the xml) here is some xml that you can pass to ConfigurationManager.ProcessConfiguration that will change the two settings:

<wap-provisioningdoc>
  <characteristic type="CM_ProxyEntries">
    <characteristic type="HTTP-{ADB0B001-10B5-3F39-27C6-9742E785FCD4}">
      <parm name="SrcId" value="{ADB0B001-10B5-3F39-27C6-9742E785FCD4}" options="My Work Network{18AD9FBD-F716-ACB6-FD8A-1965DB95B814}My ISP{ADB0B001-10B5-3F39-27C6-9742E785FCD4}Work{A1182988-0D73-439E-87AD-2A5B369F808B}Secure WAP Network{F28D1F74-72BE-4394-A4A7-4E296219390C}The WAP Network{7022E968-5A97-4051-BC1C-C578E2FBA5D9}The Internet{436EF144-B4FB-4863-A041-8F905A62C572}" />
      <parm name="DestId" value="{436EF144-B4FB-4863-A041-8F905A62C572}" options="My Work Network{18AD9FBD-F716-ACB6-FD8A-1965DB95B814}My ISP{ADB0B001-10B5-3F39-27C6-9742E785FCD4}Work{A1182988-0D73-439E-87AD-2A5B369F808B}Secure WAP Network{F28D1F74-72BE-4394-A4A7-4E296219390C}The WAP Network{7022E968-5A97-4051-BC1C-C578E2FBA5D9}The Internet{436EF144-B4FB-4863-A041-8F905A62C572}" />
      <parm name="Proxy" value="new-inet:1159" />
      <parm name="Override" value="" />
      <parm name="Enable" value="1" />
      <parm name="Type" value="0" />
      <parm name="Username" value="" />
      <parm name="Password" value="" />
      <parm name="ExtraInfo" value="" />
    </characteristic>
    <characteristic type="null-corp-{ADB0B001-10B5-3F39-27C6-9742E785FCD4}">
      <parm name="SrcId" value="{ADB0B001-10B5-3F39-27C6-9742E785FCD4}" options="My Work Network{18AD9FBD-F716-ACB6-FD8A-1965DB95B814}My ISP{ADB0B001-10B5-3F39-27C6-9742E785FCD4}Work{A1182988-0D73-439E-87AD-2A5B369F808B}Secure WAP Network{F28D1F74-72BE-4394-A4A7-4E296219390C}The WAP Network{7022E968-5A97-4051-BC1C-C578E2FBA5D9}The Internet{436EF144-B4FB-4863-A041-8F905A62C572}" />
      <parm name="DestId" value="{A1182988-0D73-439E-87AD-2A5B369F808B}" options="My Work Network{18AD9FBD-F716-ACB6-FD8A-1965DB95B814}My ISP{ADB0B001-10B5-3F39-27C6-9742E785FCD4}Work{A1182988-0D73-439E-87AD-2A5B369F808B}Secure WAP Network{F28D1F74-72BE-4394-A4A7-4E296219390C}The WAP Network{7022E968-5A97-4051-BC1C-C578E2FBA5D9}The Internet{436EF144-B4FB-4863-A041-8F905A62C572}" />
      <parm name="Proxy" value="" />
      <parm name="Override" value="" />
      <parm name="Enable" value="1" />
      <parm name="Type" value="0" />
      <parm name="Username" value="" />
      <parm name="Password" value="" />
      <parm name="ExtraInfo" value="" />
    </characteristic>
  </characteristic>
  </wap-provisioningdoc>

This was taken from my wm 6 pro emulator, so you may need to play with the settings a little. It sets both the dropdowns to My ISP (the ADB0B001-10B5-3F39-27C6-9742E785FCD4 guid) Just change the guid in the type="HTTP-xxxx" and type="null-corp-xxxx" and ensure it matches in the srcId parm too.

I called ProcessConfiguration with this xml (and metadata set to true) to get a list of all the entries that were configured, it returns them in an xml doc.

<wap-provisioningdoc>
  <characteristic-query type="CM_Mappings" recursive="true"/>
  <characteristic-query type="CM_Planner" recursive="true"/>
  <characteristic-query type="CM_Networks" recursive="true"/>
  <characteristic-query type="CM_ProxyEntries" recursive="true"/>
  <characteristic-query type="Wi-Fi" recursive="true"/>
  <characteristic-query type="CM_PPPEntries" recursive="true"/>
  <characteristic-query type="CM_VPNEntries" recursive="true"/>
  <characteristic-query type="CM_NetEntries" recursive="true"/>
  <characteristic-query type="CM_GPRSEntries" recursive="true"/>
</wap-provisioningdoc>

You can either use that to see what the guids and settings are or look in the include files from the WM sdk as they are listed there for use with the connection manager apis.

One caveat is that I haven't tried to use these connections after messing with them, but the UI does change when you process the configs

Matt
  • 2,984
  • 1
  • 24
  • 31
  • I'm giving you the check in anticipation of your DMProcessConfigXML code, and also because `ctlpnl.exe` is something I wish I had known about long ago. I just tried out your working example, and then wasted a half hour trying to use SendMessage to programmatically click through to the Network Management screen. I think it's doable, although I don't have an urgent need for it anymore. – MusiGenesis Mar 11 '10 at 02:30
  • Yeah I did notice your post date after I had answered and wondered if my answer was still relevant... I'll dig out the DMProcessConfigXML stuff and post it here – Matt Mar 11 '10 at 02:35
  • And yeah I agree with you, the network management screen config with sendmessages is doable... but just plain nasty :) – Matt Mar 11 '10 at 02:37
2

You need to use the Connection Manager API to establish a connection. In fact, there is a flag you can set to stop the error notification!

Here is an article on how to use the connection manager with wininet. I assume you will have to P/Invoke the API.

One suggestion I would have, is to abstract use the connection manager out as much as possible and it use as little of it as possible. Connection Manager is not very nice to use and I beleave the current interface is being dropped in furture versions of Windows Mobile.

Update:

Calling DMProcessConfigXML is really easy from native code. Again I assume the P/Invoke of this function into C# should not be to bad. Following the link to see a simple example of calling this the DMProcessConfigXML. The had part is figuring out from the microsoft documentation what xml you want to send.

You basically need to go through the Configuration Service Providers MSDN documentation in whatever area you can to configure. If you are looking into network setup, I personally would not bother. It's a big hairy mess and is really only useful for setting up proxy setups for specific mobile operators and/or corporate network WIFI setups. If you want to setup general GPRS / Wifi connections, it's not that easy.

Update2: I should read the question more closely, I beleave the answer is NO to "modifying the network options", but "Yes" to creating whole new network setups. That's if I understand the spec correctly. I have only played around with setting up networks.

Hope that helps.

Shane Powell
  • 13,698
  • 2
  • 49
  • 61
  • @Shane: this allows access to the DMProcessConfigXML function I mentioned in question 1. I have not yet found a sample that shows me how to use this in C# (I'm going to update my question to mention C#). – MusiGenesis Nov 19 '08 at 05:35
  • @Shane: also good advice. I generally use as little as possible of everything, and that's especially true of anything I'm PInvoking into. – MusiGenesis Nov 19 '08 at 05:37
  • I know DMProcessConfigXML is basically a function that you pass some XML to, I just don't know how to call it and what XML to pass it to get what I need. – MusiGenesis Nov 19 '08 at 05:38
  • Thanks. I still can't find a code sample anywhere for flipping those darn combo boxes. What I mainly want to replace is these painful support calls where I'm telling them "flip it one way - no, make one one way and the other the other way" and so on. If I don't even know which ones are right ... – MusiGenesis Nov 19 '08 at 06:40
  • ... so how can I expect my clients to? – MusiGenesis Nov 19 '08 at 06:40
  • The current implementation of the connection manager is WM5/6 is really bad. In talking to Microsoft about this, they admit it's a new very good and that is one reason why it's been rewritten. The new configuration manager I have seen is so much better in lots of ways. I can't say much cas of NDA. – Shane Powell Nov 19 '08 at 06:51
  • I guess I have to do what I really didn't want to do: write code that uses findwindow and sendmessage to automatically open that dialog underneath my running form. WM is still the land of the hacks. – MusiGenesis Nov 20 '08 at 22:22
  • I understand NDA. If you talk to any WM5/6 engineers, tell them I hate them. WM phones could have been the iPhone YEARS AGO if it had occured to them to make WM easy to use. – MusiGenesis Nov 20 '08 at 22:25