Public Group

# static into dll and back

This topic is 4414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey folks, once again i realy on your help! This time its about putting static arrays into a dll and how to get em back out again. The DLL compiles beatifully, however when i refer to the object in my exe, it throws me an "unresolved external symbol". Here now how i did it:
//DLLImport.h
#ifndef DECLSPEC
#define DECLSPEC _declspec(dllexport)
#else   DECLSPEC _declspec(dllimport)
#endif

DECLSPEC float mesh01_coords[];

//NEW FILE NEW FILE NEW FILE NEW FILE
//DLLImport.cpp
#include "DLLImport.h"
DECLSPEC float mesh01_coords[] = {
1, 2, 3, .... };


In the actual project I progged like this:
#define DECLSPEC
#pragma comment(lib, "MyDLL.lib");
#include "DLLImport.h"

float *mesh = mesh01_coords; //<-- Error


Does anyone have a clue what is going on, since I used the same method to put all kinds of stuff into a dll. Maybe a link to a turial, sample code or article? Thanks in advance for your help regards Woltan

##### Share on other sites
//DLLImport.h#ifndef _EXPORTS#define DECLSPEC _declspec(dllexport)#else#define DECLSPEC _declspec(dllimport)#endif

You must also define the symbol _EXPORTS when you compile the DLL, but don't define it when you're compiling exe.

##### Share on other sites
well, as far as i know, the way i do it works just as fine. The only difference is, that i do define DECLSPEC when i compile the exe and I dont when I compile my dll.
Unless I am mistaken I dont think that this is the error, since this is exactly the same way how i import my other dll into my project.
Any other suggestions?

##### Share on other sites
Quote:
 Original post by Woltanwell, as far as i know, the way i do it works just as fine. The only difference is, that i do define DECLSPEC when i compile the exe and I dont when I compile my dll.Unless I am mistaken I dont think that this is the error, since this is exactly the same way how i import my other dll into my project.Any other suggestions?

It is definitely wrong, because in your code, inside else section what you have is "DECLSPEC _declspec(dllimport)" - there is no "#define" in front of it (there's only "#else", as far as i know - everything on the same line as "#else" is ignored, so basicaly you just have an empty #else section).
//DLLImport.h#ifndef DECLSPEC#define DECLSPEC _declspec(dllexport)#else   DECLSPEC _declspec(dllimport)#endif

So that's one. Second thing is, that you are defining the same symbol twice. I don't think there are any compilers that wouldn't give you an error or at least a warning on such thing. So that is why, you should either use other symbol to indicate when to export and when to import from DLL OR you should undefine the symbol before redefining it. Here are both solutions:
1) use different symbol (my previous example):
/DLLImport.h#ifndef _EXPORTS#define DECLSPEC _declspec(dllexport)#else#define DECLSPEC _declspec(dllimport)#endif

2) undefine the symbol before redefining it:
/DLLImport.h#ifndef DECLSPEC#define DECLSPEC _declspec(dllexport)#else#undef DECLSPEC#define DECLSPEC _declspec(dllimport)#endif

NOTE: you should always compile your code with the maximum warning level and you should fix all warnings (so there is none).

##### Share on other sites
Wow,
both of you were right. And if I start thinking about it, it does make sence!
HOWEVER: I am inporting in the same method i posted up there other dlls, the only difference is, that in those there are classes and no arrays or static datatypes.
So thanks a lot again, what would I do without this community!!
Cherio Woltan

##### Share on other sites
Uhm... Both of us? I don't have split personality disorder! lol :D

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633349
• Total Posts
3011464
• ### Who's Online (See full list)

There are no registered users currently online

×