<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'How do I link a DLL to a Win32 EXE for use??' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'How do I link a DLL to a Win32 EXE for use??' posted on the 'Windows programming' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Tue, 18 Jun 2013 22:09:31 -0700</pubDate>
    <lastBuildDate>Tue, 18 Jun 2013 22:09:31 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>How do I link a DLL to a Win32 EXE for use??</title>
      <link>http://www.programmersheaven.com/mb/windows/38330/38330/how-do-i-link-a-dll-to-a-win32-exe-for-use/</link>
      <description>I'm trying to get my executeable file to load a few DLLs I have made and compiled so that I don't have to put a ton of functions into the actual executeable, but I have NO experience with DLLs. Can somebody help me figure out how to use both load-time linking (Borland says I have to link with the .LIB for this one?) and run-time linking (for stuff such as the main menu popping up when you press ESC). I would REALLY appreciate any help that anybody can give me. Thanks for your time.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-Seph&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/38330/38330/how-do-i-link-a-dll-to-a-win32-exe-for-use/</guid>
      <pubDate>Sat, 28 Oct 2000 16:55:45 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Re: How do I link a DLL to a Win32 EXE for use??</title>
      <link>http://www.programmersheaven.com/mb/windows/38330/38492/re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38492</link>
      <description>Hello Speh..&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
For linking in compile time, you only need to add the lib file to your project, then #include the header file and off you go. For example, you have a void myfunc( int x ) in the DLL, your include file will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
// mydll.h&amp;lt;br&amp;gt;&lt;br /&gt;
#if !defined( INC_MYDLL )&amp;lt;br&amp;gt;&lt;br /&gt;
#define INC_MYDLL&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
#if defined( __cplusplus )&amp;lt;br&amp;gt;&lt;br /&gt;
extern "C" {&amp;lt;br&amp;gt;&lt;br /&gt;
#endif // __cplusplus&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
// list the functions here&amp;lt;br&amp;gt;&lt;br /&gt;
void WINAPI myfunc( int x );&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
#if defined( __cplusplus )&amp;lt;br&amp;gt;&lt;br /&gt;
}&amp;lt;br&amp;gt;&lt;br /&gt;
#endif // __cplusplus&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
#endif // INC_MYDLL&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
If you have a problem with any of the above, post again!&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to use a DLL created by someone else, then dont forget to IMPLIB it beforehand. BCB and VC++ both use different format for thier import libraries.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
To use the DLL above in run-time, you would do it like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
typedef void (*WINAPI pMYFUNC)( int );&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
HINSTANCE hInst = LoadLibrary( "mydll.dll" );&amp;lt;br&amp;gt;&lt;br /&gt;
pMYFUNC pMyFunc = (pMYFUNC) GetProcAddress( hInst, "myfunc" );&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
// and run it..&amp;lt;br&amp;gt;&lt;br /&gt;
pMyFunc(10);&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
// You might want to do this before you are done&amp;lt;br&amp;gt;&lt;br /&gt;
FreeLibrary( hInst );&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
I didnt understand what you mean by main menu and ESC...&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Hope this helped a bit&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/38330/38492/re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38492</guid>
      <pubDate>Mon, 30 Oct 2000 09:53:56 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Re: Re: How do I link a DLL to a Win32 EXE for use??</title>
      <link>http://www.programmersheaven.com/mb/windows/38330/38525/re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38525</link>
      <description>OK, I didn't make a header file for the dll before.  All I did was make a file with the functions in it, and then compiled to a dll, with no errors or warnings.  So what would this header file be used for?  Just linking purposes??&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-Seph&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/38330/38525/re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38525</guid>
      <pubDate>Mon, 30 Oct 2000 17:07:09 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Re: Re: Re: How do I link a DLL to a Win32 EXE for use??</title>
      <link>http://www.programmersheaven.com/mb/windows/38330/38652/re-re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38652</link>
      <description>That header file is the interface to your DLL. Remember, a DLL is a library, and a library is all about packaging some piece of code from the user with only an interface exposed.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
For example, GDI.EXE (its a DLL renamed EXE really) is the DLL, windows.h is the interface that has the prototypes of the functions inside that DLL, like int WINAPI SetPixel( HDC hDC, int x, int y );&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
: OK, I didn't make a header file for the dll before.  All I did was make a file with the functions in it, and then compiled to a dll, with no errors or warnings.  So what would this header file be used for?  Just linking purposes??&amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;br&amp;gt;&lt;br /&gt;
: -Seph&amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/38330/38652/re-re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38652</guid>
      <pubDate>Tue, 31 Oct 2000 14:47:46 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Re: Re: Re: Re: How do I link a DLL to a Win32 EXE for use??</title>
      <link>http://www.programmersheaven.com/mb/windows/38330/38660/re-re-re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38660</link>
      <description>So it would be like this?&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
//the dll itself&amp;lt;br&amp;gt;&lt;br /&gt;
int hitval(int level, int str, int agi, int opagi)&amp;lt;br&amp;gt;&lt;br /&gt;
   {&amp;lt;br&amp;gt;&lt;br /&gt;
   stuff here;&amp;lt;br&amp;gt;&lt;br /&gt;
   return hit;&amp;lt;br&amp;gt;&lt;br /&gt;
   }&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
//the header&amp;lt;br&amp;gt;&lt;br /&gt;
*stuff you showed me here*&amp;lt;br&amp;gt;&lt;br /&gt;
int hitval(int level, int str, int agi, int opagi);&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
I'm going to try it real fast and see what happens.  This "fight.dll" is very important to the program though, considering it has all battle info in it.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-Seph&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/38330/38660/re-re-re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38660</guid>
      <pubDate>Tue, 31 Oct 2000 15:55:27 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Re: Re: Re: Re: How do I link a DLL to a Win32 EXE for use??</title>
      <link>http://www.programmersheaven.com/mb/windows/38330/38663/re-re-re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38663</link>
      <description>OK, just got done trying it.  I pasted what you posted into the header file, and changed it from INC_MYDLL to INC_FIGHT (fight.dll/fight.cpp) and the void function I replaced with "int hitval(int level, int str, int agi, int opagi);".  I am still getting "unresolved external referenced from AoY.OBJ".  I have added the .lib file to the project, to be linked with the executeable.  Any ideas??&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-Seph&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/38330/38663/re-re-re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38663</guid>
      <pubDate>Tue, 31 Oct 2000 16:08:58 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Re: Re: Re: Re: Re: How do I link a DLL to a Win32 EXE for use??</title>
      <link>http://www.programmersheaven.com/mb/windows/38330/38742/re-re-re-re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38742</link>
      <description>You still need to tell the compiler which functions to export from the DLL. This can be done in 2 ways, the __dllimport/__dllexport or through a DEF file, I use DEF files always because it lets me define the ordinal numbers of those functions myself, meaning, if I update the DLL by adding new functions, the EXE's need not to be recompiled. A good practice!&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
OK, lets write this down.. I think you know how to create a Win32 DLL project, so here are the files to add.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
First of all here's the H file:&amp;lt;br&amp;gt;&lt;br /&gt;
//----------------------------------------------------------------------------&amp;lt;br&amp;gt;&lt;br /&gt;
// fight.h&amp;lt;br&amp;gt;&lt;br /&gt;
#if !defined( INC_FIGHT )&amp;lt;br&amp;gt;&lt;br /&gt;
#define INC_FIGHT&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
#if defined( __cplusplus )&amp;lt;br&amp;gt;&lt;br /&gt;
extern "C" {&amp;lt;br&amp;gt;&lt;br /&gt;
#endif // __cplusplus&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
int WINAPI hitval(int level, int str, int agi, int opagi);&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
#if defined( __cplusplus )&amp;lt;br&amp;gt;&lt;br /&gt;
}&amp;lt;br&amp;gt;&lt;br /&gt;
#endif // __cplusplus&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
#endif // INC_FIGHT&amp;lt;br&amp;gt;&lt;br /&gt;
//----------------------------------------------------------------------------&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
And the CPP file&amp;lt;br&amp;gt;&lt;br /&gt;
//----------------------------------------------------------------------------&amp;lt;br&amp;gt;&lt;br /&gt;
// fight.cpp&amp;lt;br&amp;gt;&lt;br /&gt;
#include &amp;lt;windows.h&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
#include "fight.h"&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
extern "C"&amp;lt;br&amp;gt;&lt;br /&gt;
int WINAPI hitval(int level, int str, int agi, int opagi)&amp;lt;br&amp;gt;&lt;br /&gt;
{&amp;lt;br&amp;gt;&lt;br /&gt;
   // for a test, show values in a message box&amp;lt;br&amp;gt;&lt;br /&gt;
   char buffer[ 80 ];&amp;lt;br&amp;gt;&lt;br /&gt;
   wsprintf( buffer,&amp;lt;br&amp;gt;&lt;br /&gt;
             "level = %d\nstr = %d\nagi = %d\nopagi = %d",&amp;lt;br&amp;gt;&lt;br /&gt;
             level, str, agi, opagi );&amp;lt;br&amp;gt;&lt;br /&gt;
   MessageBox( NULL, buffer, "in dll", MB_OK );&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
   return 10;&amp;lt;br&amp;gt;&lt;br /&gt;
}&amp;lt;br&amp;gt;&lt;br /&gt;
//----------------------------------------------------------------------------&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
And the DEF file&amp;lt;br&amp;gt;&lt;br /&gt;
;----------------------------------------------------------------------------&amp;lt;br&amp;gt;&lt;br /&gt;
; fight.def&amp;lt;br&amp;gt;&lt;br /&gt;
LIBRARY        FIGHT.DLL  ; should be the same name as the result DLL!&amp;lt;br&amp;gt;&lt;br /&gt;
DESCRIPTION    'This is the fight DLL!'&amp;lt;br&amp;gt;&lt;br /&gt;
HEAPSIZE       10000&amp;lt;br&amp;gt;&lt;br /&gt;
EXPORTS&amp;lt;br&amp;gt;&lt;br /&gt;
hitval         @100   ; you can add more functions here: function name   @101 and so on&amp;lt;br&amp;gt;&lt;br /&gt;
;----------------------------------------------------------------------------&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Note that comments in DEF file are ; comment... much like ASM comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
That's it, compile/link the lot, you have a DLL and a LIB file. Now create a simple test EXE something like this&amp;lt;br&amp;gt;&lt;br /&gt;
// ----------------------------------------------------------------------------&amp;lt;br&amp;gt;&lt;br /&gt;
// test.cpp&amp;lt;br&amp;gt;&lt;br /&gt;
#include &amp;lt;windows.h&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
#include "fight.h"  // make sure this points to the correct path&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )&amp;lt;br&amp;gt;&lt;br /&gt;
{&amp;lt;br&amp;gt;&lt;br /&gt;
   int ret = hitval( 1, 2, 3, 4 );&amp;lt;br&amp;gt;&lt;br /&gt;
   char buffer[ 80 ];&amp;lt;br&amp;gt;&lt;br /&gt;
   wsprintf( buffer, "returned %d", ret );&amp;lt;br&amp;gt;&lt;br /&gt;
   MessageBox( NULL, buffer, "in exe", MB_OK );&amp;lt;br&amp;gt;&lt;br /&gt;
   return 0;&amp;lt;br&amp;gt;&lt;br /&gt;
}&amp;lt;br&amp;gt;&lt;br /&gt;
//----------------------------------------------------------------------------&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Add fight.lib to this project, make sure fight.dll is somewhere along the path, run.. It should work fine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Hope this helps&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
: OK, just got done trying it.  I pasted what you posted into the header file, and changed it from INC_MYDLL to INC_FIGHT (fight.dll/fight.cpp) and the void function I replaced with "int hitval(int level, int str, int agi, int opagi);".  I am still getting "unresolved external referenced from AoY.OBJ".  I have added the .lib file to the project, to be linked with the executeable.  Any ideas??&amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;br&amp;gt;&lt;br /&gt;
: -Seph&amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/38330/38742/re-re-re-re-re-how-do-i-link-a-dll-to-a-win32-exe-for-use/#38742</guid>
      <pubDate>Wed, 01 Nov 2000 07:51:22 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>The missing include file is windows.h (NT)</title>
      <link>http://www.programmersheaven.com/mb/windows/38330/38743/the-missing-include-file-is-windowsh-nt/#38743</link>
      <description>No text... No text... No text... No text... No text... No text...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/38330/38743/the-missing-include-file-is-windowsh-nt/#38743</guid>
      <pubDate>Wed, 01 Nov 2000 07:54:13 -0700</pubDate>
      <category>Windows programming</category>
    </item>
  </channel>
</rss>