|
Looks to me that the class is not exported properly. Can you show how you've exported the class?
Never mind - you've shown that in the first post. But the errors you get are typical of an incorrect attempt at exporting a class.
It'd be best to create a fresh example DLL (compiled as /clr) that exports a native class. Then first use it from a native caller, then try from a mixed-mode caller. That'd help you identify what you did wrong in your first project.
|
|
|
|
|
OK. I Started a solution from scratch, but I am still faced with the same issues. I think I can simplify the question, though:
Simply put, how do I import a native class from a mixed-mode DLL into a mixed-mode app? I can import a managed class easily from a /clr DLL. I can import a native class from a Win32 DLL easily. But I can't import a native class from a /clr DLL.
Thanks.
|
|
|
|
|
Xpnctoc wrote: But I can't import a native class from a /clr DLL.
There are many details involved, are you following any article or something?
led mike
|
|
|
|
|
No, I'm not following an article. Can you point me to a good one?
All of the articles I've come across are for other types of operations, such as importing a class from a Win32 DLL where you don't have access to the DLL source, going through the headache of using dumpbin.exe to find the public symbols and then constructing wrapper classes and such. But this is overkill for me.
I just need to know why, when I have reference an assembly built with the /clr option, I can import managed classes but not native ones. I just haven't found an article that address that issue from that viewpoint.
|
|
|
|
|
Xpnctoc wrote: OK. I Started a solution from scratch, but I am still faced with the same issues. I think I can simplify the question, though:
Simply put, how do I import a native class from a mixed-mode DLL into a mixed-mode app? I can import a managed class easily from a /clr DLL. I can import a native class from a Win32 DLL easily. But I can't import a native class from a /clr DLL.
I created a test DLL and a test EXE. I export a class from the DLL and use that class in the EXE. Both DLL and EXE are compiled with /clr and it works as expected.
Perhaps you have forgotten to add the export lib to the EXE project?
You can use the following line directly in your cpp file :-
#pragma comment(lib, "Path to DLL/DllName.lib")
|
|
|
|
|
Adding the #pragma directive succeeded! Thank you.
As follow up, can you tell me why the .lib has to be added to a project for exporting unmanaged classes compiled with /clr, but not if the DLL was build without CLR support? Or why in a /clr build, the .lib is required for importing unmanaged classes but not for importing stand-alone, unmanaged functions (that were surrounded with the "#pragma unmanaged" directive)?
Also, then, does the #using<> directive only pertain to managed code? Earlier I had tried adding the code #using < CliLib.dll >, but that did not help. Only referring to the .lib file solved the problem.
Could you direct me to any useful articles related to all of this?
Thanks again.
|
|
|
|
|
Xpnctoc wrote: As follow up, can you tell me why the .lib has to be added to a project for exporting unmanaged classes compiled with /clr, but not if the DLL was build without CLR support? Or why in a /clr build, the .lib is required for importing unmanaged classes but not for importing stand-alone, unmanaged functions (that were surrounded with the "#pragma unmanaged" directive)?
The lib is needed in bith scenarios. It's just that, without the /clr the VS IDE automatically uses the lib (possibly because you have a project dependency set appropriately).
It should really do the same for /clr too - but it looks like the IDE team overlooked doing that. This'd be a minor-level bug I suppose.
Xpnctoc wrote: Also, then, does the #using<> directive only pertain to managed code? Earlier I had tried adding the code #using < CliLib.dll >, but that did not help. Only referring to the .lib file solved the problem.
#using is used to access a managed assembly (including a mixed-mode assembly). It imports the managed meta data that allows us to use those types in our calling app.
It has nothing to do with exported native types.
|
|
|
|
|
I get it now. I didn't even think of the project dependency settings, and you are absolutely right that I do have a dependency set. I'm so accustomed to the IDE taking care of the LIB links that I just never even thought of it.
Thank you so much for all of your help.
|
|
|
|
|
hey guys, just a very quick question. How od i bring up a msgbox with c++. cant seem to find anyhting on the site.
Thank you VERY much.
- Droz -
___ ___
/\/\ /\ | |
|
|
|
|
|
AfxMessageBox if you're using MFC, MessageBox if you're not.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: AfxMessageBox if you're using MFC, MessageBox if you're not.
And MessageBox::Show if you are using WinForms.
|
|
|
|
|
Thank you for your time.
- Droz -
___ ___
/\/\ /\ | |
|
|
|
|
|
But who does such a thing ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: But who does such a thing ?
Come on, CG, you and I know that there are 100s of 1000s of C++ devs using WinForms with C++/CLI
|
|
|
|
|
Yeah, probably. But only because they download Express, or perhaps they live in fairyland.... :P
Ooops - this was in the managed form. My bad...
-- modified at 18:15 Friday 18th August, 2006
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
This is one of the weirdest things I've ever seen. And its been very tricky to nail down.
We instantiate a class (foo *somefoo = new foo() ) using 'new' and get a pointer to that class.
Later in code, witihin a function of another class, we 'new' a new piece of memory (char *buff = (char*) new char [buffSize]) VERY oddly, this 'new' is returning the address of "somefoo" we instantiated earlier and not a new piece of memory.
Any ideas why this is happening? Or how we can avoid this? Remarkably, its happening at the same point in code EVERY time, although we use new everywhere. This was a pain in the a#$ to find.
Help please!?!?!?!?!?
-C
|
|
|
|
|
The most obvious answer is that the particular instance of somefoo is being deleted and returning that address to the available heap prior to the char array being allocated.
led mike
|
|
|
|
|
First: how is this a C++/CLI question?
Second: what? How is it a file if it is not saved?
led mike
|
|
|
|
|
hi,
i am using Visual C++ toolkit 2003.
i am writing a windows forms application.
if i click a button , it has to call an win 32 api from windows.h, say MessageBox(),
i included #include windwos.h
now it is giving an ambiguity error WinMain is already defined,
how to get out of this, even i tried the order of
#using mscorlib.dll
# include windows.h
// i am having some assumption or workarounds for this,, but i need a solution ??
// because i am intersted in discussing about this ..
// warm welcome for the discussion
^-^
@|@
- redCat
|
|
|
|
|
Hello friends,
I have downloaded libjingle application which uses
third party component GIPS. Can we replace third party component GIPS by any
other third party component. Which must be available freely.
Thanks in Advance.
Rahul Kulkarni
|
|
|
|
|
I have an unmanaged C++ dll which is an MFC shared DLL that has functions in it to initialize sockets and do other ethernet related things. I have built a managed C++ wrapper project which is also an MFC shared DLL, compiled with /clr that calls functions in the unmanaged dll. Then I have a C# project which instantiates a member of the wrapper class to access the unmanaged functions.
One of the functions in the unmanaged dll creates a new CAsyncSocket, checks to see if AfxSocketInit is successful, and if so, calls Create to create a new socket. When I call this function through my wrapper from C#, I get a debug assertion when Create is called. The call stack trace indicates that the problem is in a call to AfxGetInstanceHandle.
I've done a lot of reading about the use of AfxGetInstanceHandle, but I can still not find any solution to this problem.
If anyone can help me out, I'd really appreciate it.
|
|
|
|
|
|
According to this, using AFX_MANAGE_STATE isn't the answer...
http://msdn2.microsoft.com/en-us/library/30c674tx.aspx[^]
It says in there:
"The AFX_MANAGE_STATE macro should not be used in regular DLLs that statically link to MFC or in extension DLLs. "
My unmanaged dll is an extension DLL, and when I attempt to use AFX_MANAGE_STATE, I get dllmain linker errors...
Does anyone else have any other ideas? I'm really stuck here and would appreciate any advise. Thank you so much,
Doreen
|
|
|
|
|
see if this article[^] will provide the details you are missing.
led mike
|
|
|
|
|
I'd like to open 500 files with OpenFileDialog with enabled multiselect. But it failes to do it throwing exception? What property to modify to open a lot of files?
9ine
|
|
|
|