I'm trying to use a Unmanaged dll (Use of MFC) into a C# project. But I know I have to wrap it before I can use it! So I've tried to wrap it without any success ! I'm new in this kind of prog and I would like some help !!!
Here is a sample of the code of the unmanaged .h I want to wrap!
Expand|Select|Wrap|Line Numbers
- #ifdef DLL_EXPORT
- #define DLL_TYPE __declspec(dllexport)
- #else
- #define DLL_TYPE __declspec(dllimport)
- #endif
- class DLL_TYPE OptiEditParam
- {
- public:
- void *param;
- OptiEditParam( void );
- ~OptiEditParam( void );
- int Edit( char *fichier, char *buffer, int &nbChar );
- };
There is other class but I want to be able to use OptiEditParam.Edit first, then I'll go for other class!
I first create a Win32 Dll, Am I Ok? Plz Help me!!
Here is the code. BTW, It compile #1...
Expand|Select|Wrap|Line Numbers
- #include "stdafx.h"
- #include "OptEbout1.h"
- #ifdef _MANAGED
- #pragma managed(push, off)
- #endif
- BOOL APIENTRY DllMain( HMODULE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
- {
- return TRUE;
- };
- OptiEditParam::OptiEditParam()
- {
- };
- OptiEditParam::~OptiEditParam()
- {
- };
- int OptiEditParam::Edit(char *fichier, char *buffer, int &nbChar)
- {
- return 0; //Is this Ok%?!!
- };
- #ifdef _MANAGED
- #pragma managed(pop)
- #endif
Then I created a Class Library And here is what I tried! But I can't get nothing except these Errors
Error 1 error C2062: type 'char' unexpected c:\documents and settings\administrator\mes documents\visual studio 2005\projects\optiwrapdll\optiwrapdll\OptiWrapDll. h 56
Error 2 error C2062: type 'char' unexpected c:\documents and settings\administrator\mes documents\visual studio 2005\projects\optiwrapdll\optiwrapdll\OptiWrapDll. h 70
Here is the code:
Expand|Select|Wrap|Line Numbers
- #pragma once
- using namespace System;
- using namespace System::Runtime::InteropServices;
- namespace OptiWrapDll {
- public struct OptiEditParamUnm
- {
- typedef struct
- {
- void (*dtor)(OptiEditParamUnm*);
- void (*Edit)(OptiEditParamUnm*);
- } __OTB;
- public:
- static __OTB *otb;
- [DllImport("Win32Dll.dll",
- EntryPoint="??0OptiEditParam@@QAE@XZ",
- CallingConvention=CallingConvention::ThisCall)]
- static void ctor(OptiEditParamUnm*);
- [DllImport("Win32Dll.dll",
- EntryPoint="??1OptiEditParam@@QAE@XZ",
- CallingConvention=CallingConvention::ThisCall)]
- static void dtor(OptiEditParamUnm*);
- [DllImport("Win32Dll.dll",
- EntryPoint="?Edit@OptiEditParam@@QAEHPAD0AAH@Z",
- CallingConvention=CallingConvention::ThisCall)]
- static int Edit(OptiEditParamUnm*,char *fichier, char *buffer, int &nbChar);
- static void Vdtor(OptiEditParamUnm* w)
- {
- dtor(w);
- }
- static void Ndtor(OptiEditParamUnm* w)
- {
- }
- static void VEdit(OptiEditParamUnm* w, char *Vfichier, char *Vbuffer, int &VnbChar)
- {
- Edit(w,Vfichier,Vbuffer,VnbChar);
- }
- };
- public ref class OptiEditParamWrap
- {
- public:
- OptiEditParamWrap()
- {
- tv = new OptiEditParamUnm();
- OptiEditParamUnm::otb->dtor = OptiEditParamUnm::Vdtor;
- OptiEditParamUnm::otb->Edit = OptiEditParamUnm::VEdit(*tv,char *Vfich, char *Vbuff, int &VnbCh);
- //char* y = (char*)(void*)Marshal::StringToHGlobalAnsi(str);
- OptiEditParamUnm::ctor(tv);
- }
- /// Let the v-table handle virtual destructor
- virtual ~OptiEditParamWrap()
- {
- OptiEditParamUnm::otb->dtor(tv);
- }
- /// Let the v-table handle method overriding
- virtual int Edit(char *Vfich, char *Vbuff, int &VnbCh)
- {
- OptiEditParamUnm::otb->Edit(*tv,char *Vfich, char *Vbuff, int &VnbCh)
- }
- private:
- OptiEditParamUnm *tv;
- };
- }
Thx A LOT!!