S
Steven Blair
Hi there.
Having a problem calling a win32 function from a dll.
Here is the function header:
DWORD thrdGetHcNum (DWORD nPort, DWORD nBaudrate, LPTSTR lpszHcNum)
//Description of the 3rd parameter
LpszHcNum: The head of the buffer area used to store the serial number
of the terminal, 9 bytes at least.
Here is my code:
[DllImport("comdll.dll", SetLastError = true)]
public static extern uint thrdGetHcNum(int nPort, int nBaudrate,
[MarshalAs(UnmanagedType.LPTStr)] ref StringBuilder lpszHcNum);
//The actual call
StringBuilder Buffer = new StringBuilder(10);
result=thrdGetHcNum(Port,Baud,ref Buffer);
Everytime I runt his, I get a Object not set to reference error.
Can anyone tell me what I am doing wrong?
I have tried using a string, a char[] buf = new[10], MarshalAs.LPTstr
and MarshalAs.Array but always hit the same problem.
I am calling other functions from the dll without any problem. The only
difference with this one is I should be getting a string back with some
data in it.
Any help on this would be appreciated.
Regards,
Steven
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Having a problem calling a win32 function from a dll.
Here is the function header:
DWORD thrdGetHcNum (DWORD nPort, DWORD nBaudrate, LPTSTR lpszHcNum)
//Description of the 3rd parameter
LpszHcNum: The head of the buffer area used to store the serial number
of the terminal, 9 bytes at least.
Here is my code:
[DllImport("comdll.dll", SetLastError = true)]
public static extern uint thrdGetHcNum(int nPort, int nBaudrate,
[MarshalAs(UnmanagedType.LPTStr)] ref StringBuilder lpszHcNum);
//The actual call
StringBuilder Buffer = new StringBuilder(10);
result=thrdGetHcNum(Port,Baud,ref Buffer);
Everytime I runt his, I get a Object not set to reference error.
Can anyone tell me what I am doing wrong?
I have tried using a string, a char[] buf = new[10], MarshalAs.LPTstr
and MarshalAs.Array but always hit the same problem.
I am calling other functions from the dll without any problem. The only
difference with this one is I should be getting a string back with some
data in it.
Any help on this would be appreciated.
Regards,
Steven
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!