473,326 Members | 2,124 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,326 software developers and data experts.

Create an instance of a class inside a c++ dll in a c# project

6
Hi everybody i really need your help im completely lost :S this is what i need:

I have a c++ dll that uses MFC.
I need to create an instance of a class inside that dll in a c# project
I need to end with another dll to add it as a reference to other projects.

I have found many "solutions" but i just get confused :S
Pinvoke (just call functions but cant create an instance...)
create a kind of proxy, wrappers or whatever (not well explained)

please orient me, wich is the best approach to do this... any url address to read?
Mar 3 '09 #1
5 3786
vekipeki
229 Expert 100+
You need to use P/Invoke to import native class members. The trickiest part here is to get the class members' names right - there is a dumpbin tool which comes with VS that will show you their names (after which you will need to "undecorate" the names using undname.exe.

You need correct native function names to specify the EntryPoint in DllImport attribute, as you can see from this example: http://blogs.msdn.com/vcblog/archive...lass-in-c.aspx
Mar 4 '09 #2
eck3ko
6
@vekipeki
can i create an instance of that way?
Mar 4 '09 #3
vekipeki
229 Expert 100+
Did you check the example? You have to P/Invoke every method from a native class, and then create a C# class which wraps these methods. If you have created a C# class, then of course you can instantiate it.

Check this example also: http://www.codeproject.com/KB/cs/marshalCPPclass.aspx.
Mar 5 '09 #4
eck3ko
6
@vekipeki
What i wanted is what is explained in the last url :D thanks a lot =), just i have a few more problems.... i just try to reproduce the same creating new projects. and when compiling the CLR c++ dll project the next error:

Error 1 fatal error C1189: #error : "include 'stdafx.h' before including this file for PCH" c:\Documents and Settings\DMendoza.AMI-GE\My Documents\Visual Studio 2005\Projects\DLLTest\DLLTest\DLLTest.h 7

This happen only when the next code is in this order:

#include "stdafx.h"
#include "DLLTest.h"
#include <STDIO.H>


#include "DLLClient2.h"

this code is in DLLClient2.cpp this project is a c++ clr dll project that will act as a proxy it creates an instance of the class that is inside the other dll (the unmanaged one). if i change the above code like this a loooot of errors shows:

#include "DLLTest.h"
#include "stdafx.h"
#include <STDIO.H>


#include "DLLClient2.h"

Error 1 error C2512: 'CDLLTestApp' : no appropriate default constructor available c:\Documents and Settings\DMendoza.AMI-GE\My Documents\Visual Studio 2005\Projects\DLLClient2\DLLClient2\DLLClient2.cpp 16

and more similar errors nothing is recognized as if the .h file doesnt exist. any ideas? ...

i already copy the unmanaged dll in the same folder
Mar 5 '09 #5
eck3ko
6
hi the last problem was solved when using the correct project type, but now i cant compile for this error:

Error 1 error PRJ0050: Failed to register output. Please ensure you have the appropriate permissions to modify the registry. DLLClientTest

any ideas? im logged as administrator
Mar 9 '09 #6

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

Similar topics

3
by: David MacQuigg | last post by:
I am writing a chapter for teaching OOP in Python. This chapter is intended as a brief introduction to replace the more complete discussion in Learning Python, 2nd ed, pp. 295-390. I need to...
5
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
4
by: Ray | last post by:
I want to dynamically load DLLs (created from VB) and instantiate a class with a particular name, like "ProcessClass". I am able to load the DLL and confirm there is a class by that name BUT I...
13
by: bonk | last post by:
Hello, I am trying to create a dll that internally uses managed types but exposes a plain unmanaged interface. All the managed stuff shall be "wrapped out of sight". So that I would be able to...
1
by: otto | last post by:
I have a technical question about WebServices. I have a solution with several projects (.exe and .dll). Each project have references to several webservices. I want to know if is possible to create...
2
by: Jordi Julià | last post by:
Hello, I need to create with VB2005 an instance of one of the classes of the project in run time. For example: - The Namespace root and the name of the project are he himself: "Project" -...
4
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one...
2
by: chandan | last post by:
Hi friends, I wanted to create object of the class which was outside of App_Code folder , but i am not able to create the instance of that class.. can we do that into Asp.Net 2.0 , C# How to...
5
by: Andy B | last post by:
I am trying to figure out how to make an object instance available for all methods of a class. I tried to do something like this: public class test { TheObject Instance = new TheObject();...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.