HighTechTalks DotNet Forums  

Using a C++ managed DLL in a J# module.

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss Using a C++ managed DLL in a J# module. in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Stéphane Postollec
 
Posts: n/a

Default Using a C++ managed DLL in a J# module. - 03-01-2005 , 07:44 AM






Hi,

First i will explain the architecture of my program.

I use an old program which is composed of several modules in Native C++.
All of these modules provides a DLL in Native C++.
We can call them :

DLLModuleNativeC++_XX

Next i want to use these DLL in another Module (a kind of wrapper for
the J# module). And this new module is a Managed C++ module in which i
use the objects provided by the different DLLModuleNativeC++_XX modules.
This module provide a Managed Mixed DLL (an assembly in fact) which will
be used by the main program in J#

We can call it :

DLLModuleManagedMixedC++

Then in my J# program I create an instance of the object
DLLModuleManagedMixedC++ and I call its functions.

My problem is that it doesn't work. So i would like to know if it
possible to do what i've done and if it the case how to make it work.

The problems encountered during the compîlation are only warning but the
problem will become from these warning

Génération de code en cours...
Compilation des ressources en cours...
Édition des liens en cours...
msvcrtd.lib(checkclr.obj) : warning LNK4210: la section .CRT existe ; il
se peut qu'il y ait des terminateurs ou des initialiseurs static non gérés
msvcrtd.lib(secchk.obj) : warning LNK4210: la section .CRT existe ; il
se peut qu'il y ait des terminateurs ou des initialiseurs static non gérés
libcpmtd.lib(xlock.obj) : warning LNK4210: la section .CRT existe ; il
se peut qu'il y ait des terminateurs ou des initialiseurs static non gérés
libcpmtd.lib(cout.obj) : warning LNK4210: la section .CRT existe ; il se
peut qu'il y ait des terminateurs ou des initialiseurs static non gérés
libcpmtd.lib(iosptrs.obj) : warning LNK4210: la section .CRT existe ; il
se peut qu'il y ait des terminateurs ou des initialiseurs static non gérés
libcpmtd.lib(locale0.obj) : warning LNK4210: la section .CRT existe ; il
se peut qu'il y ait des terminateurs ou des initialiseurs static non gérés

In english : warning LNK4210: .CRT section exists; there may be
unhandled static initializers or terminators

Moreover the method which create the instance of
DLLModuleManagedMixedC++ in my J# program is a static method so i think
the problem becomes from theses warning.


But it's only warning and when i lauched my program, it crashs.

The error during the execution (when i want to enter in the function who
create an instance of DLLModuleManagedMixedC++ is :

An exeception of type 'System.IO.FileNotFoundException' is done in the
MAIN.ex (program J#)
The file or the assembly named DLLModuleManagedMixedC++ or one of its
dependances are not found.

Thus i'm asking if my DLLModuleManagedMixedC++ works fine and have
included all the dll provides by all the DLLModuleNativeC++_XX.


To resume i would like to know if i can use DLL in native C++ in a
module with mixed Native and Managed C++ which provides a Managed DLL
that i can use directly in my J# program (i can see the object
DLLModuleManagedMixedC++ and create an new one : i have done a namespace)


So thanks in advance and i hope you will find a solution to my problem
because i run out of idea !!

Steph

Reply With Quote
  #2  
Old   
Stéphane Postollec
 
Posts: n/a

Default Re: Using a C++ managed DLL in a J# module. - 03-02-2005 , 03:58 AM






First thanks for your explanation.

I have all the source code of the old dll. All the modules providing
these dll are included in my solution J#

Solution J#

Native
Module Native DLL 1
Module Native DLL 2
...
Module Native DLL 8

Managed
Module C++ Managed (Wrapper using the differents
Module Native DLL X)

And in the solution J# I import the assembly provided by the managed
code and i make an instance of it. My problem is not here but during the
execution. My idea is the Managed DLL seems to not link with the code
provided by the Native DLL Module.
I remember you the error in the Runtime :

""" An exeception of type 'System.IO.FileNotFoundException' is done in
the MAIN.exe (program J#)
The file or the assembly named DLLModuleManagedMixedC++ or one of its
dependances are not found. """

To answer your questions :

Lars-Inge Tønnessen [VJ# MVP] a écrit :

-----------------------------------------------------------------
1]> Not easy to say when we don't see your code. But double check that
any of
Quote:
your code does not hard code any paths to any dlls. Eg in the managed C++
part.

Yes i know it's difficult without the code but i can't show you the code
because it's a commercial project.
But what do you mean with "hard code any paths to any dlls" ?

2]> Search through all your dll projects to locate any CRT sections. Can
you
Quote:
locate them?

I can find all the CRT section in the native dll code but i don't want
to touch this code (it's a big project that i've to include in my
project). I can only work at the level of the Wrapper managed Module.

Quote:
Using a managed C++ dll in J# is like using any other .NET dll. Make a
reference (in the menu: "project" + "Add Reference...") to the dll-file and
make an instance of it, and do method calls.

Yes it's already done (see previous explanations)

Quote:
Do you have the source code for the old C++ dlls ? Would it be hard to
convert it into a ATL C++ COM components? If you can convert it (the old C++
code) into a COM component you can drop the managed C++ layer. It's very
easy to reference and use a COM component in J#.


Yes i have the source code but like i said i don't want to modify hardly
the dll code. I can make some small modification but not converting them
in ActiveX.
Moreover i don't know how to do it and will take me too much time to do
it (it's a commercial project so i have deadlines !)

Quote:
Are you able to show us a small code sample of your code ?
No sorry. I can only say you that the DLL Native C++ comes from a
project of ten years (so you can easily understand that i don't want to
modify it !).
But in fact, first I only want to know how to use old DLL ( Entry point
etc..) in a mixed managed C++ Module. I have seen an example on the
microsoft MSDN called MCppWrapper.
First when i compile the Microsoft code directly i've got this warning
LINK : warning LNK4243: DLL containing objects compiled with /clr is not
linked with /NOENTRY; image may not run correctly

To understand how it works, I've only duplicated the code in the native
C++ (the same code but i only rename the substring class with
mysubstring and i've done the same thing in the Managed mixed module (i
create a new __gc class) but i got
Exception 'System.StackOverflowException' in test.dll done by this line
char * in_string = new char[length+1];

Thanks in advance.


Quote:

Regards,
Lars-Inge







Reply With Quote
  #3  
Old   
Stéphane Postollec
 
Posts: n/a

Default Re: Using a C++ managed DLL in a J# module. - 03-03-2005 , 04:31 AM



Lars-Inge Tønnessen [VJ# MVP] a écrit :
Quote:
I helped one programmer at work to day with a similar problem.

His problem was that the dll's where not included in the search path. We
added the search path (eg. "C:\blabla\blabla\") to the path environment
variable in the "Control Panel" + "System" + "Advanced" + "Environment
variables" + "System" + "path"

Does this work ?


Regards,
Lars-Inge


Hi,

Yes you're right since i add the path to all my DLL in the system Path
variable, my program don't crash and don't give me the Error message
talking about missing dependancy.
Now i have to test if i can use the function from my differents NATIVE
C++ DLL.
I will inform you as soon as i finish to test it.
If it's this problem you save me !
Thanks.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.