Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

links to dll sites 2

Status
Not open for further replies.

sumedha

Programmer
Apr 12, 2000
15
LK
hi,<br>anyone know of any links to sites which gives instructions on how to write dlls in vc++?<br>sumedha
 
Microsoft own MSDN would be able to help, writing an ActiveX dll, or control would be easier, unless you plan on sticking it into a language that cant use OCX(activeX) <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
hi,<br><br>Writing dlls are very simple,<br><br>In VC create a Win32 application, go to setting and in the linker options add &quot;/dll&quot; (without quotes) and your file will get linked as a dll not an exe. <br><br>now include a new file with an .c or .cpp extension and add it to the project. also add a .def file.<br><br>Theory says you need to have a DllMain like WinMain but you don't need one. Dll is a binary file with functions. so add your functions in a dll. open the .def file and you need to set up the exports section.<br><br>This is how you will do it.<br>in .def file<br><br>Exports <br>&nbsp;FunctionOne<br>&nbsp;FunctionTwo<br><br><br>that's all. Click on Build all , you will be able to create a dll. remember &quot;/dll&quot; option in link setting. <br><br>Now you need to call the dll in a client.(exe file)<br><br>this is a sample code, so change it to suit your needs.<br><br>HANDLE hMod ;<br>hMod = LoadLibrary(&quot;path of your dll(including filename)&quot;) ;<br><br>// Assuming signature of your FunctionOne(in dll) is like //this<br>// int FunctionOne(char *,char *) , it can be any way !!<br>// create a typedef for your function pointer<br><br>typedef int (FunctionOne *)(char *,char *) ;<br><br>// create an object of type FunctionOne to hold the address <br>// of your function in the dll<br><br>FunctionOne a ;<br><br>// Now load that pointer with the actual address of the //function<br>a = (FunctionOne)GetProcAddress(hMod,&quot;FunctionOne&quot;) ;<br><br>// now a is loaded with the address of the dll<br>// call a<br><br>// remember FunctionOne takes two char pointers<br>int nRet = a(&quot;hello&quot;,&quot;World&quot;) ;<br><br><br> <p>GuruPrasad Belthur<br><a href=mailto:belthurgp@yahoo.com>belthurgp@yahoo.com</a><br><a href= Personal Page</a><br>Commerce Graduate, but have lived purely on computers. All the work i have done till now is only with computers and I love it.
 
Very nice explaination. But should this line:

typedef int (FunctionOne *)(char *,char *) ;

be like this?

typedef int (*FunctionOne)(char *,char *);

Or am I missing something.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top