473,500 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Call LoadLibrary/GetProcAddress?

I have some C functions I need to expose as XML web services. My original
plan was to deply an XML Web service in C# and use P/Invoke to call my C
functions. This is not working because the web service cannot find the DLL
in the same directory.

This is probably because the DLL needs to be in a different directory,
perhaps the same directory as ASP.NET or \WinNT\System32. Unfortunately,
placing my DLL in these directories is not an option because I'm using a
hosting service.

Since I'm not getting any response from my queries in the WebServices forum
I guess I need to take another approach.

I know how to explicitly specify the full path of a DLL when calling
LoadLibrary/GetProcAddress when using C++. Is it possible to call my C
functions in their DLL using C# with LoadLibrary/GetProcAddress? What does
GetProcAddress return, a delegate? How does C# deal with function pointers?

Siegfried
Nov 16 '05 #1
3 61110
Check this out...
http://www.codeproject.com/csharp/dyninvok.asp
Regards
-Amit
"Siegfried Heintze" <si*******@heintze.com> wrote in message
news:OR*************@TK2MSFTNGP10.phx.gbl...
I have some C functions I need to expose as XML web services. My original
plan was to deply an XML Web service in C# and use P/Invoke to call my C
functions. This is not working because the web service cannot find the DLL
in the same directory.

This is probably because the DLL needs to be in a different directory,
perhaps the same directory as ASP.NET or \WinNT\System32. Unfortunately,
placing my DLL in these directories is not an option because I'm using a
hosting service.

Since I'm not getting any response from my queries in the WebServices forum I guess I need to take another approach.

I know how to explicitly specify the full path of a DLL when calling
LoadLibrary/GetProcAddress when using C++. Is it possible to call my C
functions in their DLL using C# with LoadLibrary/GetProcAddress? What does
GetProcAddress return, a delegate? How does C# deal with function pointers?
Siegfried

Nov 16 '05 #2
Yes, its possible to call those functions from c#

you have to use DllImport for that.

[DllImport("kernel32")]
public extern static int LoadLibrary(string librayName);

[DllImport("kernel32", CharSet=CharSet.Ansi)]
public extern static int GetProcAddress(int hwnd, string procedureName);

The usage example is

//load the library user32
int hwnd=LoadLibrary("User32");

//get the proc address of messageboxW
int addr=GetProcAddress(hwnd, "MessageBoxW");
Shak.

"Siegfried Heintze" <si*******@heintze.com> wrote in message
news:OR*************@TK2MSFTNGP10.phx.gbl...
I have some C functions I need to expose as XML web services. My original
plan was to deply an XML Web service in C# and use P/Invoke to call my C
functions. This is not working because the web service cannot find the DLL
in the same directory.

This is probably because the DLL needs to be in a different directory,
perhaps the same directory as ASP.NET or \WinNT\System32. Unfortunately,
placing my DLL in these directories is not an option because I'm using a
hosting service.

Since I'm not getting any response from my queries in the WebServices forum I guess I need to take another approach.

I know how to explicitly specify the full path of a DLL when calling
LoadLibrary/GetProcAddress when using C++. Is it possible to call my C
functions in their DLL using C# with LoadLibrary/GetProcAddress? What does
GetProcAddress return, a delegate? How does C# deal with function pointers?
Siegfried

Nov 16 '05 #3
If you don't mind hardcode paths, just specify the full path of your DLL in
the DllImport, eg.
DllImport["d:\\somedir\\some.dll"]
Another option is to include the dll's path in the PATH environment.

Willy.

"Siegfried Heintze" <si*******@heintze.com> wrote in message
news:OR*************@TK2MSFTNGP10.phx.gbl...
I have some C functions I need to expose as XML web services. My original
plan was to deply an XML Web service in C# and use P/Invoke to call my C
functions. This is not working because the web service cannot find the DLL
in the same directory.

This is probably because the DLL needs to be in a different directory,
perhaps the same directory as ASP.NET or \WinNT\System32. Unfortunately,
placing my DLL in these directories is not an option because I'm using a
hosting service.

Since I'm not getting any response from my queries in the WebServices
forum
I guess I need to take another approach.

I know how to explicitly specify the full path of a DLL when calling
LoadLibrary/GetProcAddress when using C++. Is it possible to call my C
functions in their DLL using C# with LoadLibrary/GetProcAddress? What does
GetProcAddress return, a delegate? How does C# deal with function
pointers?

Siegfried

Nov 16 '05 #4

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

Similar topics

1
3182
by: sunil s via DotNetMonster.com | last post by:
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...
9
2147
by: bclegg | last post by:
Hi, I am a VB.net programmer who has to make use of a 3rd party Borland C++ dll. We have a successful VC++ wrapper that presents a number of functions that can be declared and called in VB.net ...
8
21223
by: ATS | last post by:
HOWTO Implement LoadLibrary\GetProcAdrress\FreeLibrary in C# Please help, I want to fully implement LoadLibrary\GetProcAdrress\FreeLibrary in C#, and be able to call functions that I use...
3
6481
by: ATS | last post by:
HOWTO Implement LoadLibrary, GetProcAdress, and FreeLibrary. Below is code that I want to be able to use simple LoadLibrary\GetProcAddress\FreeLibrary technqiues on. I've used the code that was...
1
3466
by: Craig Dunstan | last post by:
I am using C# to write a web service, which relies on some underlying functionality in a third party DLL. I have been reliably informed that I should not use static binding to the DLL as this will...
1
10171
by: Siegfried Heintze | last post by:
I have some C functions I need to expose as XML web services. My original plan was to deply an XML Web service in C# or VB and use P/Invoke to call my C functions. This is not working because the...
1
1614
by: Vic.Dong | last post by:
Hi all: I call windows api LoadLibrary(), it returns error code : ERROR_NOACCESS 0x3E6, why is it failure to call this api? how to fix this problem? B.G. Vic
3
2751
by: Vic.Dong | last post by:
Hi all: I call windows api LoadLibrary(), it returns error code : ERROR_NOACCESS 0x3E6, why is it failure to call this api? how to fix this problem? B.G. Vic
0
5366
by: Mike S | last post by:
I've seen examples of using the CallWindowProc Windows API function to call functions through their addresses in VB6 -- a clever workaround to emulate C-like function pointer semantics. A...
0
7021
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
7207
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
7242
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
7401
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4928
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3112
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
318
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.