473,386 Members | 1,673 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,386 software developers and data experts.

.net dll call from native c++

Hi,

I've got a native C++ app which calls a 3rd parth .NET DLL using the
LoadLibrary/GetProcAddress functions. This works fine when the DLL is
located in the app directory, but if I move it out to it's own directory,
then I get a FileNotFoundException. I've tried manipulating the
app.exe.config file's <codebase> parameter, but this doesn't seem to have
any effect, possibly because the DLL does not have a strong name. The only
thing that does work is manipulating the DEVPATH variable/machine.config
file, but I don't think that this is what DEVPATH was designed for. I
cannot guarantee where the app will be run from but I do know that the DLL
will always be found in a fixed directory path. How do I get my app to
read the DLL?

Sunil

--
Message posted via http://www.dotnetmonster.com
Jul 21 '05 #1
1 3173
sunil s via DotNetMonster.com wrote:
Hi,

I've got a native C++ app which calls a 3rd parth .NET DLL using the
LoadLibrary/GetProcAddress functions. This works fine when the DLL is
located in the app directory, but if I move it out to it's own
directory, then I get a FileNotFoundException. I've tried
manipulating the app.exe.config file's <codebase> parameter, but this
doesn't seem to have any effect, possibly because the DLL does not
have a strong name. The only thing that does work is manipulating
I am a bit unsure about what you are doing. You have an unmanaged C++
process and you want to load a managed library assembly. How are you
executing the code? How do you load the managed classes in the managed
library assembly? Are you hosting the runtime and using COM interop to
get the class?

Why are you using GetProcAddress? GetProcAddress is for unmanaged
exported functions (__declspec(dllexport)) not for managed, __clrcall,
methods. If the managed DLL is written in managed C++ then you can put
__declspec(dllexport) on a global function that will be compiled to IL
and get access to it via GetProcAddress. When the function is called the
runtime will be initialized, however, DO NOT DO THIS! There is a serious
bug in .NET and Windows that will potentially cause a deadlock. This bug
won't be fixed until Whidbey. You can get round this bug (the mixed mode
loader bug), but it involves separate initialization of unmanaged global
variables and the CRT, and its messy.

As to your question. Fusion is a replacement for
LoadLibrary/GetProcAddress and the sections in the config file are used
to configure Fusion. Those settings have no effect at all on
LoadLibrary. LoadLibrary is configured through the PATH environment
variable and a redirect file (an empty file with the name of the process
and .local as the extension that indicates that LoadLibrary should only
pick up DLLs from the application folder).
the DEVPATH variable/machine.config file, but I don't think that this
is what DEVPATH was designed for. I cannot guarantee where the app
will be run from but I do know that the DLL will always be found in a
DEVPATH is a horrible hack, and as you have said, it is not intended for
doing what you are trying to do. It will be removed in later versions of
..NET
fixed directory path. How do I get my app to read the DLL?


I need more information about what you are trying to do. From, your
description I think that you are trying to call a global function in a
library assembly that contains IL and has been exported with
__declspec(dllexport) if this is the case you are storing up trouble. It
would be better to export a static method from a class, host the runtime
and call the COM Callable Wrapper.

Here's a tutorial on Fusion that you might find useful and explains some
of the issues I have mentioned above:

http://www.grimes.demon.co.uk/workshops/fusionWS.htm

Richard
--
www.richardgrimes.com
my email ev******@zicf.bet is encrypted with ROT13 (www.rot13.org)
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike Kamzyuk | last post by:
Hello all. Basically, I need to call a mixed-mode dll's function (which uses managed code) from a native or mixed-mode dll function (which does not use managed code). I'm wondering if this could...
8
by: Paul | last post by:
Hi all may I know how to use C# DLL inside my VC++ Project ? Thanks in advance.
3
by: Richard A. Lowe | last post by:
Hi all (sorry I haven't been around lately for those who know me, life happens :) I have to call a native DLL (written > 5 years ago, not by me, and all source lost) that is currently being...
1
by: Tim Rogers | last post by:
We've currently got a C++ client/server app that uses DCOM in order to make remote calls. We want to replace DCOM with a .NET Web Service. The server piece seems clear to me. I can write it...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
2
by: Marek | last post by:
Hi I'm trying to call a native C++ dll using the following code (both C# and C++ code segments included). When I make the call to the method (AddTwoDoubles) that has no return value all is fine. ...
28
by: Peter Olcott | last post by:
I want to double check my understanding about how the .NET framework works. From what I understand every call to the .NET framework is ultimately translated into one of more API calls, is this...
4
by: Steve Richter | last post by:
I have a C++ forms project that I am adding some unmanaged code to. I have a member function of the Form1 class that returns a String^ holding the text of the last win32 error. The code is...
1
by: cctv.star | last post by:
I need to dynamically load and call .NET assembly from native application, written in C++. I'm trying to do this by creating a (managed) module, written in C++/ CLI, whose header can be...
5
by: =?Utf-8?B?SmVmZg==?= | last post by:
Well - from my initial research, this doesn't seem to be an easy solution if it is doable at all. I have .NET 2.0 C# Classes compiled into DLLs. I also have older unmanaged (non-.NET) C++ code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.