English 中文(简体)
从C#申请中取出的自动电离机
原标题:calling win32 dll api from C# application

我已经制作了一个双筒,从我们的服务器中发送和检索数据包,我正在使用P/Invoke机制,从我负责所有必要任务的“C# app”中抽取一个小数功能。

当我打电话“联通”(char* lpPostData)

如果我使用Cchar* lpPostData作为从我C#的附录中发出的寄出的参数,要求它做工,则我使用静态的果园阵列作为邮寄要求。 C# string to char*? 如果是这样的话? 如何减少温32的死亡人数?

www.un.org/Depts/DGACM/index_spanish.htm 将出口职能从C# app上调:

[DllImport("testdllwm6.dll", EntryPoint = "Connect")]   public
static extern int pConnect(string postdata);

string postdata="<SyncML><SyncHdr><VerDTD>1.2</VerDTD><VerProto>SyncML/1.2</VerProto><SessionID>33622878</SessionID><MsgID>1</MsgID><Target><LocURI>http://sync.com</LocURI></Target><Source><LocURI>IMEI::358997011403172</LocURI><LocName>syncfdg</LocName></Source><Meta><MaxMsgSize
xmlns="syncml:metinf">10000</MaxMsgSize></Meta></SyncHdr><SyncBody><Alert><CmdID>1</CmdID><Data>201</Data><Item><Target><LocURI>contacts</LocURI></Target><Source><LocURI>./contacts</LocURI></Source><Meta><Anchor
xmlns="syncml:metinf"><Last>000000T000000Z</Last><Next>20091125T122400Z</Next></Anchor></Meta></Item></Alert><Final></Final></SyncBody></SyncML>";

int j = pConnect(postdata);

<> 宣布:

__declspec(dllexport) int Connect(char* lpPostData);

www.un.org/Depts/DGACM/index_spanish.htm 该职能被定义为:。

__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 = &sizeInResult;
LPDWORD pSizeOutResult = &sizeOutResult;
LPDWORD pSizeToWrite = &sizeToWrite;
LPDWORD pSizeWritten = &sizeWritten;  int read = 0;


char postData[637]
="<SyncML><SyncHdr><VerDTD>1.2</VerDTD><VerProto>SyncML/1.2</VerProto><SessionID>66622878</SessionID><MsgID>1</MsgID><Target><LocURI>http://sync.com</LocURI></Target><Source><LocURI>IMEI::358997011403172</LocURI><LocName>new123</LocName></Source><Meta><MaxMsgSize
xmlns="syncml:metinf">10000</MaxMsgSize></Meta></SyncHdr><SyncBody><Alert><CmdID>1</CmdID><Data>201</Data><Item><Target><LocURI>contacts</LocURI></Target><Source><LocURI>./contacts</LocURI></Source><Meta><Anchor
xmlns="syncml:metinf"><Last>000000T000000Z</Last><Next>20091125T122400Z</Next></Anchor></Meta></Item></Alert><Final></Final></SyncBody></SyncML>";
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;
问题回答

失败之处非常明显。 Windows CE是Unicode。 C#中的插座是一阵,C的果园是多的。 你把两者混为一谈,这是坏的、坏的、坏的。

我指的是你以同样的呼吁重新组合,向HttpSendRequest派遣了大头和多边的海报? 这当然是正确的。

• 改变“连接”功能,以视此:

int Connect(TCHAR* lpPostData) 

它再次尝试,并重获结果。

当然,这也意味着你也需要改变大声呼吁。

作为附带说明,我不理解你为什么要把这一呼吁推向C++。 你可以从你的C# app那里正确做。

看来批号是中西太平洋渔委的延期票,可能只有中西太平洋渔委的申请才能被叫来。 i 不能确定。

C# string to char*?

Net Interopmarer使用的CharSet是Ansi。

If you want use Unicode(LPCWSTR) parameters, you can try:

[DllImport("testdllwm6.dll", EntryPoint = "Connect", CharSet=CharSet.Unicode)] 
public static extern int pConnect(string postdata);

BTW, you can refer to .Net 2.0 Interoperability Recipes: A Problem-Solution Approach for more information.

你们需要把沉积的参数添加到沼泽地。 该网络的运行时间知道它如何消散;由于违约的扼杀被 mar为统法协会编码,但你希望ANSI:

[DllImport("testdllwm6.dll", EntryPoint="Connect")]
public static extern int Connect([MarshalAs(UnmanagedType.LPStr)] string lpPostData);

用途

System.Text.StringBuilder

页: 1





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签