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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a dll?

Status
Not open for further replies.

SLider3

Programmer
Jun 17, 2003
56
PT
Hi

I need a speedy dll that parses a string and returns a substring.
The dll sould contain a function in order to be called by one program, like this:

Parsestring(String, Ldelimiter, Rdelimiter, Number, Action)

legend:
Parsestring is the function name, and returns the substring.
String is the input string to parse.
Ldelimiter is the left delimiter of the substring (is a string).
Rdelimiter is the right delimiter (is a string).
Number is the number of substrings if there are more than one substring contained by the same delimiters.


My bigest problem is that i've never made a dll before and i dont know it works. What kind of code i need to write? How to create the dll???

And then i need to know how to use the imformation on the dll. How should i cll the function in the dll on my program??
 
So why does it need to be a DLL instead of an ordinary function in the code?

It just seems to me to be adding a level of complexity which isn't needed.

DLL's are entirely compiler specific, so if you still want more info, then I suggest you post in the Microsoft Visual C++ forum forum116

--
 
Well Salem is right, you dont need a DLL for this kind of thing. But if you readlly want to jump in for it, you can use VC++. When you chose the type of applications to be created, choose for DLL.

Rest C/C++ is same irrespective of whether you are creating a dll or a exe out of that.
 
Well....i really need to make a dll.

Yeah...i select new dll and then? I probaby wont understande the extra code. Could you give me more info or a place where i can find it?

And still don´t know how to call the function on the dll. How should i include the dll in my project (i´m using BCB, it matters?).

Other thing....can you give me some help to do function i said? if somone at least give me an ideia how to do it will be very good.

Thanks.
 
MFC dll?? don't thinks so (i have never made a dll before). And i still don't know how to do it. :-(

I can use the same dll in a BCB program and in a VB program??

What about the function?? Can someone help me with that??
 
As Salem and gasingh said you find a lot of books about dlls and there is a little bit complex process depending on what you want. But, because you insist , here is a very simple example that I did for you using C++ Microsoft Dev Studio.

-Open VC++ Dev Studio
-Files->New->Projects tab -> Select Win 32 Dynamic Link Library; Choose a project name ;Let say ParseString ;Click Ok;
-Step 1 of 1 -> Check An empty DLL project->Finish->Ok
At this time you have an empty project created \ParseString folder and there some project files such as: ParseString.dsp and ParseString.dsw
Add files to the ParseString project:
1. File->New -> Files-> Select C/C++ Header File (Make sure Add to project check box in on and the project name is there) ->Type ParseString in the Filename->Click Ok
Paste there the following code (ParseString.h):


#ifndef __PARSESTRING_H
#define __PARSESTRING_H
#ifndef __PARSESTRING__
#define __PARSESTRINGLIB__ __declspec(dllimport)
#else
#define __PARSESTRINGLIB__ __declspec(dllexport)
#endif

__PARSESTRINGLIB__ char * ParseString( char *, char *, char *,int, int );


#endif

2. File->New -> Files-> Select C/C++ Source File (Make sure Add to project check box in on and the project name is there) ->Type ParseString in the Filename->Click Ok
Paste there the following code (ParseString.cpp):

#include <afx.h>
#define __PARSESTRING__
#include &quot;PARSESTRING.h&quot;

__PARSESTRINGLIB__ char * ParseString( char * str, char * Ldelim, char * Rdelim, int Number, int Action )
{
// Add your code here
return str;
}
Now , if you explore the project you will see the ParseString.h and ParseString.cpp files created in the \ParseString folder

3. Now build the &quot;parsestring.dll&quot; file :
From main menu select : Build->ParseString.dll or F7
You should have no errors and the result are two important files : \ParseString\debug\parsestring.lib
and \ParseString\debug\parsestring.dll
4. Close project: File->Close Workspace

How to test the parsestring.dll ?

1. File->New->Projects tab->Win32 Console application-> Type a project name; Let say TestParseString
--Step 1 of 1 -> Check An empty project->Finish->Ok
At this time you have an empty project created \TestParseString folder and there some project files such as: TestParseString.dsp and TestParseString.dsw
2. Add files to the TestParseString project:

File->New -> Files-> Select C/C++ Source File (Make sure Add to project check box in on and the project name is there) ->Type TestParseString in the Filename->Click Ok
Paste there the following code (TestParseString.cpp):

#include <iostream.h>
#include &quot;parsestring.h&quot;
int main()
{
cout << ParseString(&quot;George&quot;, &quot;&quot;,&quot;&quot;,0,0)<< endl ;
return 0;
}

3. Build the TestParseString.exe : Build->TestParseString.exe . You cannot link.
Copy the ParseString.h and ParseString.lib files in the \TestParseString folder
Now the TestParseString project should compile and link
The results is \TestParseString\debug\testparsestring.exe file created
4. Try to run it: Build-> Execute TestParseString.exe or CTRL+F5
You will get error about parsestring.dll file.
5. Copy parsestring.dll file into the \TestParseString\debug\ folder
6. Run TestParseString.exe . It should display &quot;George&quot; on the console screen.

-obislavu-


 
@obislavu
Thanks for your help.

If i want to do a C dll i use the same 'defines'? and just need to put C code in &quot;ParseString.cpp&quot; instade of C++ code? There is any real importante diference?

I could use the same dll in a VB and VC++ program? doesn't matter the language i code the dll?


Do anyone know e-boks where i can find more imformation about dlls (how to make it, etc)?


PS: I someone could give help me or just give me some ideas to make the function (in C) would be very good. Anybody?
 
Yes, you still to use the same defines and includes.
Use .h and .lib to link it in other project.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top