Re: How to use a C++ class in .NET
- From: "Herbert Saal" <hsaal@xxxxxxxx>
- Date: Wed, 20 Jul 2005 14:34:39 -0400
Thank u very much Lloyd!
"Lloyd Dupont" <ld@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:OpnMC7SjFHA.2472@xxxxxxxxxxxxxxxxxxxxxxx
> 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...
>
> "Herbert Saal" <hsaal@xxxxxxxx> wrote in message
> news:ug7UXwSjFHA.3316@xxxxxxxxxxxxxxxxxxxxxxx
>> Hello,
>>
>> I have a c++ class in a dll. like this one:
>>
>> class __declspec(dllexport) MyClass
>> {
>> private:
>> public:
>> MyClass(void);
>>
>> int funtion1(unsigned char * inBuffer, unsigned int inType, unsigned char
>> *outBuffer, int& out_Size);
>> int function2(void *inBuffer_a, void *inBuffer_b, unsigned long int
>> *outResult);
>> };
>>
>> Note that the function parameters are prefixed with "out" and "in"
>> depending of the parameter.
>>
>> I tried to use the class with the DLLImport functionality but it doesn't
>> works, i'm not sure if i have to use this with classes.
>> I'm working with c#.
>>
>> Please help me.
>>
>> Regards,
>> Herbert
>>
>
>
.
- References:
- How to use a C++ class in .NET
- From: Herbert Saal
- Re: How to use a C++ class in .NET
- From: Lloyd Dupont
- How to use a C++ class in .NET
- Prev by Date: HttpWebRequest connecting to tivo webserver
- Next by Date: Re: HttpWebRequest connecting to tivo webserver
- Previous by thread: Re: How to use a C++ class in .NET
- Next by thread: OnStop timing out, service manager terminating process?
- Index(es):
Relevant Pages
|