PInvoking C++ is not very common.
For one thing you could ONLY PInvoke C++ dell compiled with Microsoft
compiler.
It's not MS fault at all, it's just due to C++ name mangling which is
absolutely compiler dependant.
It's the same issue that a C++ DLL is only usable with the same compiler.
Anyway you've got 3 solutions:
- it's a C++ dll compiled with CL (doesn't looks like it though, CL favor
def file over dllexport), you could theoritically call them directlry using
CallingConvention.ThisCall, however it's not very much documented, and I'm
not quite sure how it works pratically
- make a C wrapper and use standart interop
- make a Managed C++ wrapper. Managed C++ v2 beta 2 is adviced, much cleaner
than v1 and has been standardized with ECMA (unlike Managed C++ v1)
to make a Managed C++ wrapper you don't need to do much changes.
maybe all you have to do is rewrite your class like that:
public ref class MyClass
{
public:
int funtion1(unsigned char* inBuffer, unsigned inType, unsigned char*
outbuf, int% out_size);
}
or much cleaner (because the above def would be seen as 'byte*" in C#)
public ref class MyClass
{
private:
int funtion1(unsigned char * inBuffer, unsigned int inType, unsigned char
*outBuffer, int& out_Size);
public:
int funtion1(array<unsigned char>^ inBuffer, unsigned inType,
array<unsigned char>^ outbuf, int% out_size)
{
pin_ptr<unsigned char> p_inbuf = &inBuffer[0];
pin_ptr<unsigned char> p_out = &outbuf[0];
pin_ptr<unsigned char> p_out_size = &out_size;
funtion((unsigned char*)p_inbuf, inType, (unsigned char)p_out,
*p_out_size);
}
}
I start to forget my managed C++ already so you better check it out on MS
web site first...
> Hello,
>
[quoted text clipped - 23 lines]
> Regards,
> Herbert
Herbert Saal - 20 Jul 2005 19:34 GMT
Thank u very much Lloyd!
> PInvoking C++ is not very common.
> For one thing you could ONLY PInvoke C++ dell compiled with Microsoft
[quoted text clipped - 72 lines]
>> Regards,
>> Herbert