473,461 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DLLs and C

114 100+
Does anyone know how to call DLL functions using C?
eg. PlaySound
MessageBox
Jul 16 '07 #1
5 1974
weaknessforcats
9,208 Expert Mod 8TB
1) Call LoadLibrary() to load the DLL.
2) Call GetProcAddress() to get the address of your function from the DLL. You will need the HMODULE from LoadLibrary() and a string with the function name. This address will be returned as a FARPROC.
3) Declare a function pointer of the correct arguments and return type.
4) Assign the FARPROC to this function pointer using a typecast.
5) Call your function using the pointer.
6) Call FreeLibrary() when you are done with the DLL and want to unload it. Use the HMODULE from LoadLibrary()
Jul 16 '07 #2
Firecore
114 100+
Could you please explain a bit more?
Jul 17 '07 #3
JosAH
11,448 Expert 8TB
Could you please explain a bit more?
I don't even speak Microsoft C, and even I could understand what WFC's
explanation is all about:

Expand|Select|Wrap|Line Numbers
  1. // 1) Call LoadLibrary() to load the DLL.
  2. HMODULE myLib= LoadLibrary("myDLL" /* maybe more params here */);
  3.  
  4. // 2) Call GetProcAddress() to get the address of your function from the DLL. 
  5. // You will need the HMODULE from LoadLibrary() and a string with the function 
  6. // name. This address will be returned as a FARPROC.
  7. FARPROC myAddr= LoadLibrary(myLib, "myFunc");
  8.  
  9. // 3) Declare a function pointer of the correct arguments and return type.
  10. typedef int (*foo_t)(double); // or whatever
  11.  
  12. // 4) Assign the FARPROC to this function pointer using a typecast.
  13. foo_t foo= (foo_t)myAddr;
  14.  
  15. // 5) Call your function using the pointer.
  16. printf("%d\n", foo(42.54);
  17.  
  18. // 6) Call FreeLibrary() when you are done with the DLL and want to unload it. 
  19. // Use the HMODULE from LoadLibrary()
  20. FreeLibrary(myLib);
  21.  
kind regards,

Jos
Jul 17 '07 #4
Firecore
114 100+
I don't even speak Microsoft C, and even I could understand what WFC's
explanation is all about:
Oh Ok..............
Maybe you coulkd but I could not.
I guess I need a lot more work eh?
And is Microsoft C the same as Turbo C from Borland?
Jul 17 '07 #5
JosAH
11,448 Expert 8TB
Oh Ok..............
Maybe you coulkd but I could not.
I guess I need a lot more work eh?
And is Microsoft C the same as Turbo C from Borland?
I guess not; that LoadLibrary() function is a Microsoft-ism as far as I know; If the
Borland folks are a bit clever they'd use the POSIX standard dlopen(), dlclose()
and dlsym() method names.

kind regards,

Jos
Jul 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Johann Blake | last post by:
I can hardly believe I'm the first one to report this, but having gone through the newsgroup, it appears that way. I would like to open a solution in the VS.NET IDE that consists of multiple...
2
by: Shiraz | last post by:
Hi I just made an installer for an application that uses two external COM dlls. On the surface, everything seems to be running smoothly and the the application runs without any errors. However,...
11
by: Devender Khari | last post by:
Hi Friends, I'm facing a situation as follows, need help on identifying possible issues. There is an MFC application developed in VC6.0, say ABCVC6.exe and another developed in VC.NET, say...
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
7
by: Oenone | last post by:
I'm sure there's an obvious way to do this, but I'm missing it so far. I have an ASP.NET application that relies on several DLLs to work. Currently in order to get my site working I have to put...
6
by: Brian Bischof | last post by:
I'm having troubles getting the debugging process to work consistenly for external classes. I got it to work once and then I turned it off. But now I can't get re-enabled. Here is what I'm doing....
0
by: Dave | last post by:
Hello The application I'm building an installer for uses dlls which were developed originally in C. Since the application itself is developed in C#, these dlls were wrapped using SWIG....
7
by: Jeff Lynn | last post by:
Help! I recently upgraded my VS V6 to VS 2005 and was unable to build projects that were perfectly ok under VS V6. Where VS 2005 fails was in the linker resolving external DLLs, which are Open...
3
by: gopal | last post by:
I am developing an application in CSharp - windows forms based, which copies the DLLs both unmanaged and managed DLLs from a shared folder and will overwrite the existing versions of managed &...
10
by: =?Utf-8?B?UmljaGFyZA==?= | last post by:
Hi, I usually deploy my ASP .NET application to the server by publishing, using Visual Studio 2005 publish feature. This creates the Bin folder on the server, with the compiled DLLs. I've...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.