title: calling win32 dll api from C# application
body: <p>I have created a win32 dll which sends and recieves ssl data packets from our server, I am calling a dll function using P/Invoke mechanism from my C# app which does all necessary tasks.</p>
  
  <p>When I call Connect(char* lpPostData) </p>
  
  <p>function and I use static char  postData [] array as a posting request it works fine , if I use   char* lpPostData as sent parameter from my C# app for posting request it doesn't works. Is it something with conversion of C# string to char * ?? if that is the case how do i do it ??  How to debug the in Win32 dll ???</p>
  
  <p><strong>Calling the exported function from C# app:</strong>    </p>
  
  <pre><code>[DllImport("testdllwm6.dll", EntryPoint = "Connect")]   public
  static extern int pConnect(string postdata);
  
  string postdata="&lt;SyncML&gt;&lt;SyncHdr&gt;&lt;VerDTD&gt;1.2&lt;/VerDTD&gt;&lt;VerProto&gt;SyncML/1.2&lt;/VerProto&gt;&lt;SessionID&gt;33622878&lt;/SessionID&gt;&lt;MsgID&gt;1&lt;/MsgID&gt;&lt;Target&gt;&lt;LocURI&gt;http://sync.com&lt;/LocURI&gt;&lt;/Target&gt;&lt;Source&gt;&lt;LocURI&gt;IMEI::358997011403172&lt;/LocURI&gt;&lt;LocName&gt;syncfdg&lt;/LocName&gt;&lt;/Source&gt;&lt;Meta&gt;&lt;MaxMsgSize
  xmlns=\"syncml:metinf\"&gt;10000&lt;/MaxMsgSize&gt;&lt;/Meta&gt;&lt;/SyncHdr&gt;&lt;SyncBody&gt;&lt;Alert&gt;&lt;CmdID&gt;1&lt;/CmdID&gt;&lt;Data&gt;201&lt;/Data&gt;&lt;Item&gt;&lt;Target&gt;&lt;LocURI&gt;contacts&lt;/LocURI&gt;&lt;/Target&gt;&lt;Source&gt;&lt;LocURI&gt;./contacts&lt;/LocURI&gt;&lt;/Source&gt;&lt;Meta&gt;&lt;Anchor
  xmlns=\"syncml:metinf\"&gt;&lt;Last&gt;000000T000000Z&lt;/Last&gt;&lt;Next&gt;20091125T122400Z&lt;/Next&gt;&lt;/Anchor&gt;&lt;/Meta&gt;&lt;/Item&gt;&lt;/Alert&gt;&lt;Final&gt;&lt;/Final&gt;&lt;/SyncBody&gt;&lt;/SyncML&gt;";
  
  int j = pConnect(postdata);
  </code></pre>
  
  <p><strong>Declaration is:</strong></p>
  
  <pre><code>__declspec(dllexport) int Connect(char* lpPostData);
  </code></pre>
  
  <p><strong>The function is defined as:</strong></p>
  
  <pre><code>__declspec(dllexport) int Connect(char* lpPostData) {
  
  LPCTSTR lpszAgent = _T("CeHttp"); 
  DWORD dwError;   DWORD sizeInResult,
  sizeOutResult, sizeToWrite,
  sizeWritten,dwRead;   HINTERNET
  hInternet=NULL;   HINTERNET
  hConnect=NULL;  HINTERNET
  hRequest=NULL;  LPDWORD
  pSizeInResult = &amp;sizeInResult;
  LPDWORD pSizeOutResult = &amp;sizeOutResult;
  LPDWORD pSizeToWrite = &amp;sizeToWrite;
  LPDWORD pSizeWritten = &amp;sizeWritten;  int read = 0;
  
  
  char postData[637]
  ="&lt;SyncML&gt;&lt;SyncHdr&gt;&lt;VerDTD&gt;1.2&lt;/VerDTD&gt;&lt;VerProto&gt;SyncML/1.2&lt;/VerProto&gt;&lt;SessionID&gt;66622878&lt;/SessionID&gt;&lt;MsgID&gt;1&lt;/MsgID&gt;&lt;Target&gt;&lt;LocURI&gt;http://sync.com&lt;/LocURI&gt;&lt;/Target&gt;&lt;Source&gt;&lt;LocURI&gt;IMEI::358997011403172&lt;/LocURI&gt;&lt;LocName&gt;new123&lt;/LocName&gt;&lt;/Source&gt;&lt;Meta&gt;&lt;MaxMsgSize
  xmlns=\"syncml:metinf\"&gt;10000&lt;/MaxMsgSize&gt;&lt;/Meta&gt;&lt;/SyncHdr&gt;&lt;SyncBody&gt;&lt;Alert&gt;&lt;CmdID&gt;1&lt;/CmdID&gt;&lt;Data&gt;201&lt;/Data&gt;&lt;Item&gt;&lt;Target&gt;&lt;LocURI&gt;contacts&lt;/LocURI&gt;&lt;/Target&gt;&lt;Source&gt;&lt;LocURI&gt;./contacts&lt;/LocURI&gt;&lt;/Source&gt;&lt;Meta&gt;&lt;Anchor
  xmlns=\"syncml:metinf\"&gt;&lt;Last&gt;000000T000000Z&lt;/Last&gt;&lt;Next&gt;20091125T122400Z&lt;/Next&gt;&lt;/Anchor&gt;&lt;/Meta&gt;&lt;/Item&gt;&lt;/Alert&gt;&lt;Final&gt;&lt;/Final&gt;&lt;/SyncBody&gt;&lt;/SyncML&gt;";
  LPCWSTR lpszHeaders =_T("Content-Type: application/vnd.sync+xml");  
  BOOL bResult; 
  
  if(!HttpSendRequest(hRequest,lpszHeaders,wcslen(lpszHeaders),
                      lpPostData,strlen(lpPostData)))
  {
  
      dwError = GetLastError();  
      printf(" not HttpSendRequest");  
      return read;
  }
  
  return read;
  </code></pre>