Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Programming Talk / C++ / C# - Creating a DLL With Visual C++ 2008 Express Edition

Author
Message
Xenocythe
18
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 7th Mar 2008 01:44
I searched the forums and google, and both have led me to nowhere.

I'm sure this must be possible...

Can anyone take me step by step to start me off with creating a DLL to work with DBPro using Visual C++ 2008 Express Edition?

Thanks.


Sig by BiggAdd.
Dr Schnitzengruber
16
Years of Service
User Offline
Joined: 19th Jul 2007
Location: C:/Projects/failed/ schnitzengruber
Posted: 7th Mar 2008 04:33
Okay, here it goes:

1) Create a new empty project (with nothing in it)

2) In the solution explorer, right click on the solution(should be second from top) and click properties.

3) In the top of the properties window click configuration manager.

4) Set the active solution configuration to release and close the configuration manager.

5) In the properties window, click "Configuration Properties->General"

6) Set "Project defaults->Configuration Type" to dynamic link library.

7) Close the properties window.

8) Add a source file(.cpp) somewhere in the solution.

9) Add this code to it:



10) Create your dll functions. All functions accessible to dark basic must be marked with DLLEXPORT before the declaration.

11) To test your code, compile the solution and copy the output dll file to any darkbasic projects folder. You can use it with the call dll and load dll commands. When using the call dll command, the entry point name is the same as the name of the function in c++.

Xenocythe
18
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 7th Mar 2008 04:43
Thanks very much

A couple more questions;

Is it only accessable through load dll? Can I drop it in the plugins user folder, and let it work it's own magic?

The most confusing part is yet to be making the dll functions. Can you give a small example, such as an Add() function, that adds two numbers together?

Thank you very much so far. You've cleared quite a lot up.


Sig by BiggAdd.
Dr Schnitzengruber
16
Years of Service
User Offline
Joined: 19th Jul 2007
Location: C:/Projects/failed/ schnitzengruber
Posted: 7th Mar 2008 04:52
Quote: "Is it only accessable through load dll?"


No, you have to add a resource file to make it a plug-in. But I never do that so I have no clue how.

Quote: "The most confusing part is yet to be making the dll functions. Can you give a small example, such as an Add() function, that adds two numbers together?"




Xenocythe
18
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 7th Mar 2008 05:00
Oh, I see, that bit of code was quite simple.

Well, I've figured out that Visual C++ 2008 Express Edition does not allow resource editing with the free version. You can, however, add a text file, and save it as .rc for a string table I presume.

Does anyone know how I can use that text file .rc trick to make a string table? What should the string table file look like, say, for that add function?


Sig by BiggAdd.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 7th Mar 2008 12:14
Quote: "Well, I've figured out that Visual C++ 2008 Express Edition does not allow resource editing with the free version."

Right-click the file in the editor and select view source.

Quote: "Does anyone know how I can use that text file .rc trick to make a string table?"

Add a file (of any type) to the project, and rename the extension in the IDE.

Quote: "What should the string table file look like, say, for that add function?"


Assuming you use extern "C" to export the function with an undecorated name:



jinzai
17
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 7th Mar 2008 14:59 Edited at: 7th Mar 2008 23:07
It is an accepted best practice to start string resource values at 101. Lower IDs are already taken by Windows. That is not usually a problem, but it can be if you start using Windows components. It is always a good idea to play well with Windows.

Having said that, here is my bit on how to create a DLL with VC++ 2008:


Replace projectname with the name of the project.
Hope that helps.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 7th Mar 2008 16:47
I'm using decorated names with VC++ 2008 express.
You can find them by opening the DLL with notepad and then search them (CTRL + F) by function name. They're always preceeded by ? and split by (a) space(s).

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Xenocythe
18
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 7th Mar 2008 21:37
Alright, I'm getting somewhere

Thanks Benjamin for the string table info, Shnitz for starting me off, and jinzai for the awesome tutorial as well.

I only have one problem. Following jinzai's advice, I added resource.h to the project with this code:


When I build, I get an error in my string table code:


It highlights IDS_STRING101 and says that it's undefined. I'm sure that resource.h and the string table are saved and added to the project. What's the dealio?


Sig by BiggAdd.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 7th Mar 2008 23:00
You need to #include resource.h at the top of the resource file.

jinzai
17
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 7th Mar 2008 23:07
oops, thanks Benjamin!
Xenocythe
18
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 7th Mar 2008 23:31


I knew it was something simple like that. I just assumed everything was auto included into everything.

------AFTER TESTING-------
Well, I included that file, then I ran into a whole bunch of errors with the 'define' code, blah blah... so I put the resource.h 'define' code at the top of the string rable .rc file, replacing the 'include'. All I need is the string table .rc code, which now looks like this:


I built the plugin, successfully, put it in plugins-user, and wa-la! I my add command worked great




Thanks big time everyone. I really appreciate all the help.



Thanks,
Xeno


Sig by BiggAdd.
jinzai
17
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 7th Mar 2008 23:38 Edited at: 7th Mar 2008 23:39
You're welcome. FYI, that is also Luke Escude's trouble...it is caused by cut and paste. When you do that, there is no carriage return at the end of the line, and the compiler gets confused. If you put the cursor at the end of the line and press enter, it will not have those errors.
Xenocythe
18
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 7th Mar 2008 23:51
Oh snap

I'll just do that.

Say, if I have two commands... does it look like this?


Also, if L is integer in a string table, S would be string, right?

Thank you.


Sig by BiggAdd.
jinzai
17
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 8th Mar 2008 00:07
Yes, it does. Certainly, you are free to name the ID anything reasonable. By convention, strings are "IDS_" something...menus are "IDM_" something, controls are "IDC_" something, etc.

Yes on #2 as well.

Login to post a reply

Server time is: 2024-04-19 21:54:21
Your offset time is: 2024-04-19 21:54:21