473,386 Members | 1,799 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.

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 61086
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
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
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
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
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
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
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
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
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
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
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.