dlls

Can somebody help me on how to use dll's?
Say in one dll i have a hello world script and in the other i have a script that runs the dll? can anyone tell me how to do that?
C++ isn't a scripting language.

You'll have to either use the Windows' API, or link the associated .lib library. The API path is more annoying, so I suggest you link the .lib instead, unless you don't mind the API path.

Finally, giving a tutorial on linking depends on the IDE of choice.

Wazzak
I don't think he meant "script" as in a scripting language. That's pretty obvious from the post.

If you are using MS visual, then create a new project, but select DLL and don't make an empty project. It'll put the basic framework in there for you.

This is sort of the basic stuff you'll need which is DLL specific:
1
2
3
4
5
#ifdef MY_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif 



You now have something called My_API which will let you export your functions or objects. Stick this in front of your object definitions.

im using code blocks...
when i create a dll it give a main.cpp and main.h the main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "main.h"

// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
    MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}


main.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef __MAIN_H__
#define __MAIN_H__

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus
extern "C"
{
#endif

void DLL_EXPORT SomeFunction(const LPCSTR sometext);

#ifdef __cplusplus
}
#endif

#endif // __MAIN_H__


By script i ment program
Here is a "hello world" example:

main cpp of the .exe project:
1
2
3
4
5
#include "DLL_Header.h"
int main()
{
    myFunction();
}


Common header (included in .exe and .dll projects)
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef DLL_Header
#define DLL_Header

#ifdef MY_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif

MY_API void myFunction();

#endif //DLL_Header 


DLL source file:
1
2
3
4
5
6
7
#define MY_EXPORTS
#include "DLL_Header.h"
#include <iostream>
MY_API void myFunction()
{
    std::cout << "Hello World" << std::endl;
}
Last edited on
I know only this. I create a dll like:
1
2
3
4
#define export extern "C" __declspec (dllexport)
export (type) function(argumentz) {
    //stuff
    }

As for reading, I'm wondering myself.
I don't get it :(
How can I transfer:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    
    cout << "Hello World" << endl;
    system("PAUSE >nul");
    return 0;
}
Topic archived. No new replies allowed.