473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Unmanaged C++ Dll To Managed

1
Here is my problem!
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
  1. #ifdef DLL_EXPORT
  2. #define DLL_TYPE __declspec(dllexport)
  3. #else
  4. #define DLL_TYPE __declspec(dllimport)
  5. #endif
  6.  
  7. class DLL_TYPE OptiEditParam
  8. {
  9.     public:
  10.         void *param;
  11.         OptiEditParam( void );
  12.         ~OptiEditParam( void );
  13.         int Edit( char *fichier, char *buffer, int &nbChar );
  14. };


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
  1. #include "stdafx.h"
  2. #include "OptEbout1.h"
  3.  
  4. #ifdef _MANAGED
  5. #pragma managed(push, off)
  6. #endif
  7.  
  8. BOOL APIENTRY DllMain( HMODULE hModule,
  9.                        DWORD  ul_reason_for_call,
  10.                        LPVOID lpReserved
  11.                      )
  12. {
  13.     return TRUE;
  14. };
  15.  
  16. OptiEditParam::OptiEditParam()
  17. {
  18. };
  19.  
  20. OptiEditParam::~OptiEditParam()
  21. {
  22. };
  23.  
  24.  
  25. int OptiEditParam::Edit(char *fichier, char *buffer, int &nbChar)
  26. {
  27.     return 0; //Is this Ok%?!!
  28. };
  29.  
  30. #ifdef _MANAGED
  31. #pragma managed(pop)
  32. #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
  1. #pragma once
  2.  
  3. using namespace System;
  4. using namespace System::Runtime::InteropServices;
  5.  
  6. namespace OptiWrapDll {
  7.  
  8.     public struct OptiEditParamUnm
  9.     {
  10.         typedef struct
  11.         {
  12.             void (*dtor)(OptiEditParamUnm*);
  13.             void (*Edit)(OptiEditParamUnm*);    
  14.         } __OTB;
  15.  
  16.     public:
  17.         static __OTB *otb;
  18.  
  19.         [DllImport("Win32Dll.dll", 
  20.                   EntryPoint="??0OptiEditParam@@QAE@XZ",
  21.                   CallingConvention=CallingConvention::ThisCall)]
  22.         static void ctor(OptiEditParamUnm*);
  23.         [DllImport("Win32Dll.dll", 
  24.                   EntryPoint="??1OptiEditParam@@QAE@XZ",
  25.                   CallingConvention=CallingConvention::ThisCall)]
  26.         static void dtor(OptiEditParamUnm*);
  27.         [DllImport("Win32Dll.dll", 
  28.                   EntryPoint="?Edit@OptiEditParam@@QAEHPAD0AAH@Z",
  29.                   CallingConvention=CallingConvention::ThisCall)]
  30.         static int Edit(OptiEditParamUnm*,char *fichier, char *buffer, int &nbChar);
  31.  
  32.         static void Vdtor(OptiEditParamUnm* w)
  33.         {
  34.             dtor(w);
  35.         }
  36.         static void Ndtor(OptiEditParamUnm* w)
  37.         {
  38.  
  39.         }
  40.         static void VEdit(OptiEditParamUnm* w, char *Vfichier, char *Vbuffer, int &VnbChar)
  41.         {
  42.             Edit(w,Vfichier,Vbuffer,VnbChar);
  43.         }
  44.  
  45.     };
  46.  
  47.     public ref class OptiEditParamWrap
  48.     {
  49.     public: 
  50.         OptiEditParamWrap()
  51.         {
  52.             tv = new OptiEditParamUnm();
  53.             OptiEditParamUnm::otb->dtor = OptiEditParamUnm::Vdtor;
  54.             OptiEditParamUnm::otb->Edit = OptiEditParamUnm::VEdit(*tv,char *Vfich, char *Vbuff, int &VnbCh);
  55.  
  56.             //char* y = (char*)(void*)Marshal::StringToHGlobalAnsi(str);
  57.             OptiEditParamUnm::ctor(tv);
  58.         }
  59.         /// Let the v-table handle virtual destructor
  60.         virtual ~OptiEditParamWrap()
  61.         {
  62.             OptiEditParamUnm::otb->dtor(tv);
  63.         }        
  64.         /// Let the v-table handle method overriding
  65.  
  66.         virtual int Edit(char *Vfich, char *Vbuff, int &VnbCh)
  67.         {
  68.             OptiEditParamUnm::otb->Edit(*tv,char *Vfich, char *Vbuff, int &VnbCh)
  69.         }
  70.  
  71.     private:
  72.         OptiEditParamUnm *tv;
  73.     };
  74.  
  75. }
  76.  
  77.  
Can you guys help me?! Would be appreciate!!!

Thx A LOT!!
Feb 28 '07 #1
0 1620

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
5
by: Chris Kiechel | last post by:
I am writing a .NET Windows application and it needs to perform DDE calls to a legacy system. I created a C++ unmanaged class that performs the actual DDE connection and communication. However,...
2
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
2
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking afterwards with ILDASM at what is visible in those assemblies from a...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
6
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
2
by: Jon Slaughter | last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for functions one can use DLLimport but how does one go about doing it for classes? Do I have to completely reimplement the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.