Click here to Skip to main content
15,916,431 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalmultiple list control Pin
abdulsoni9-Dec-03 1:24
abdulsoni9-Dec-03 1:24 
Generalimage processing Pin
satadru9-Dec-03 0:59
satadru9-Dec-03 0:59 
GeneralRe: image processing Pin
KaЯl9-Dec-03 2:25
KaЯl9-Dec-03 2:25 
GeneralI want to export global data in a DLL Pin
Matthew Busche9-Dec-03 0:54
Matthew Busche9-Dec-03 0:54 
GeneralRe: I want to export global data in a DLL Pin
KaЯl9-Dec-03 2:18
KaЯl9-Dec-03 2:18 
GeneralRe: I want to export global data in a DLL Pin
Matthew Busche9-Dec-03 6:20
Matthew Busche9-Dec-03 6:20 
GeneralRe: I want to export global data in a DLL Pin
KaЯl9-Dec-03 7:00
KaЯl9-Dec-03 7:00 
GeneralRe: I want to export global data in a DLL Pin
Matthew Busche9-Dec-03 8:42
Matthew Busche9-Dec-03 8:42 
KaЯl,

Thanks very much for your sample code! I've got it working now. You never mentioned anything about dllimport! That was my problem. From my experimentation, I now believe the following:


  • For global data (certainly for built-in data types and I presume this goes for global C++ objects as well), the DLL source code module must declare the data using __declspec(dllexport), BUT the application module must declare the data using __declspec(dllimport). This seems a tad annoying since the header file must look different for the DLL compile and the Application compile.

  • For functions (and I presume this goes for class declarations as well), the DLL source code must likewise declare the function using __declspec(dllexport), BUT IN CONTRAST TO THE CASE FOR DATA the application can declare the function using __declspec(dllimport), __declspec(dllexport), or nothing at all!


Actually I just found the dllimport/dllexport descriptions in the MSDN that would seem to support my claims, though I find it somewhat cryptic -- the kind of description that makes sense only after you already know what it's trying to describe. Maybe I'm just mentally slow or lazy. I will have to read the entire section a time or two to see what I can learn.

Anyway, here is what I did for my source code to get this to work.

----- stupidDll.h -----
#ifndef STUPIDDLL_H
#define STUPIDDLL_H
#ifndef DllDecl
#define DllDecl __declspec(dllimport)
#endif
int DllDecl getStupidInt();
extern DllDecl int x;
#endif
-------------------------

----- stupidDll.cpp -----
#define DllDecl __declspec(dllexport)
#include "stupidDll.h"
int x = 8;
int foo = 7;
int getStupidInt() { return foo; }
-------------------------

----- stupidApp.cpp -----
#include "stupidDll.h"
#include "stdio.h"
int main(){
printf("%d %d\n", getStupidInt(), x);
return 0;
}
-------------------------

As you can see, my DllDecl macro normally expands to __declspec(dllimport); however, I predefined the DllDecl macro in StupidDll.cpp before the #include "StupidDll.h" to force it to instead expand to __declspec(dllexport).

Thanks again for your help. It was most helpful.

Matt
GeneralRe: I want to export global data in a DLL Pin
KaЯl9-Dec-03 9:38
KaЯl9-Dec-03 9:38 
GeneralRe: I want to export global data in a DLL Pin
Alexander M.,9-Dec-03 4:53
Alexander M.,9-Dec-03 4:53 
GeneralRe: I want to export global data in a DLL Pin
Matthew Busche9-Dec-03 6:24
Matthew Busche9-Dec-03 6:24 
QuestionAny way out......??? Pin
satadru9-Dec-03 0:51
satadru9-Dec-03 0:51 
AnswerRe: Any way out......??? Pin
Shanmuga Sundar9-Dec-03 1:56
Shanmuga Sundar9-Dec-03 1:56 
GeneralFirst-chance exception in GH_DBM_COMDLL_Stub_MFC_EXE.exe: 0xC0000005: Access Violation Pin
derik_konark9-Dec-03 0:39
derik_konark9-Dec-03 0:39 
GeneralRe: First-chance exception in GH_DBM_COMDLL_Stub_MFC_EXE.exe: 0xC0000005: Access Violation Pin
Mike Dimmick9-Dec-03 3:29
Mike Dimmick9-Dec-03 3:29 
GeneralHELP PLEASE! Pin
bhangie9-Dec-03 0:24
bhangie9-Dec-03 0:24 
GeneralRe: HELP PLEASE! Pin
David Crow9-Dec-03 2:59
David Crow9-Dec-03 2:59 
GeneralRe: HELP PLEASE! Pin
Alexander M.,9-Dec-03 4:51
Alexander M.,9-Dec-03 4:51 
Generalhook functions in another process Pin
RicoH8-Dec-03 23:06
RicoH8-Dec-03 23:06 
GeneralRe: hook functions in another process Pin
jmkhael8-Dec-03 23:23
jmkhael8-Dec-03 23:23 
GeneralRe: hook functions in another process Pin
RicoH8-Dec-03 23:32
RicoH8-Dec-03 23:32 
GeneralRe: hook functions in another process Pin
jmkhael8-Dec-03 23:44
jmkhael8-Dec-03 23:44 
GeneralRe: hook functions in another process Pin
RicoH8-Dec-03 23:50
RicoH8-Dec-03 23:50 
GeneralRe: hook functions in another process Pin
jmkhael9-Dec-03 0:16
jmkhael9-Dec-03 0:16 
GeneralRe: hook functions in another process Pin
RicoH9-Dec-03 0:19
RicoH9-Dec-03 0:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.