Re: PInvoke Marshalling....



Daniel,

Actually, it's not pretty obvious. In C++, long corresponds to a 32-bit
integer, which in C#, is an int. Also, you should declare how your strings
are marshaled in the DllImport attribute. All-in-all, your declaration
should look like this:

[DllImport("Dependencies\\SNAPI.DLL", CharSet=CharSet.Ansi)]
public static extern int SNAPI_SetVersionBuffer(IntPtr DeviceHandle,
StringBuilder pData, int max_length);

Also, if the pData parameter is not going to be written to by the API
function, you can pass it as a string.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx


"Daniel Bass" <danREMOVEbass@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:u83rn0XFIHA.1056@xxxxxxxxxxxxxxxxxxxxxxx
Greetings!

I'm trying to call this method in a c# app...

SNAPIDLL_API int __stdcall SNAPI_SetCapabilitiesBuffer(HANDLE
DeviceHandle, unsigned char *pData, long max_length);

So far I've got this:
[DllImport("Dependencies\\SNAPI.DLL")]
public static extern int SNAPI_SetVersionBuffer(IntPtr DeviceHandle,
StringBuilder pData, long max_length);

Keep getting a PInvokeStackImbalance error and I think it's the 2nd
paramter pData because I've referenced the device handler and the long
typedef is pretty obvious.

For the 2nd paramter I've tried the following without success:
byte[]
char[]
string
StringBuilder
[MarshalAs(UnmanagedType.AnsiBStr)] string

HELP!
Thanks.
Dan.



.



Relevant Pages

  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • RE: Controling Modal Dialogs (Solution)
    ... doesn't return until the 'modal' browser returns. ... string varOptions) ... public void DocumentComplete ... int rc = winDisp.Invoke(rgDispId, ref guid, 0, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Gcc compatible header file
    ... A string collection is a table of zero terminated strings that will grow ... typedef struct _StringCollection StringCollection; ... int; ... bool; ...
    (comp.lang.c)
  • Kernighan and Pikes "Beautiful" Code
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • Re: FTP CD command
    ... public const int GENERIC_WRITE = 0x40000000; ... string lpszProxyName, ... public static extern IntPtr InternetConnect ( ... public static extern bool FtpGetCurrentDirectory ( ...
    (microsoft.public.dotnet.languages.vb)