Home > Software engineering >  VS2015 different simulate DLL global variable transmission error, the DLL function is no problem?
VS2015 different simulate DLL global variable transmission error, the DLL function is no problem?

Time:09-24


A module is C
A.H
 extern int _declspec (dllexport) test_dllGlobalVar1; 

A.C

 test_dllGlobalVar1=100; 


Hope module B calls test_dllGlobalVar1

Module B is a WIN32 console application, including

1, stdafx. H
 # pragma once 
# include "targetver. H"
# include & lt; stdio.h>
# include & lt; Tchar. H>
Extern "C" {
# include "test_dllGlobalvar. H"
}


2, the biggest pp
 # pragma comment (lib, a. "ib") 
Extern int _declspec (dllimport) test_dllGlobalVar1;
Int main ()
{
Test_dllGlobalVar1=100;
}


A module a. ib and a. d. ll is already good, and the other functions can be B right call, is there A problem is A global variable, compilation of B prompt DLL links, then connect the run into the error, the following error message

Severity code shows line project file
Error LNK2001 cannot resolve the external symbol of _test_dllGlobalVar1 B D: \ Test_Program \ B.o bj 1
Severity code shows line project file
Warning C4273 "test_dllGlobalVar1" : DLL links inconsistent B d: \ test_program \ biggest pp 25
Severity code shows line project file
1 error LNK1120 cannot resolve the external command B D: \ Test_Program \ Debug \ B.e xe 1

Why is that? Yesterday, I all right call over a period of time (DLL global variables and DLL function calls), then don't know which changed the environment Settings, has been around the error, function DLL call has been no problem, is a global variable has a problem, please directly,


CodePudding user response:

 extern int _declspec (dllexport) test_dllGlobalVar1 () 
{
The return of 100;
}

CodePudding user response:

reference 1st floor xuddk727 response:
extern int _declspec (dllexport) test_dllGlobalVar1 ()
{
The return of 100;
}


Function is allowed, but the way I want to achieve global variables

CodePudding user response:

The # pragma data_seg (" Shared ")
The static LONG test_dllGlobalVar1=100;
# pragma data_seg ()

CodePudding user response:

The
reference 3 floor schlafenhamster response:
# pragma data_seg (" Shared ")
The static LONG test_dllGlobalVar1=100;
# pragma data_seg ()


Or not, tested the DLL in the macro, function can be, is not a global variable, and continue to guide

CodePudding user response:

LONG test_dllGlobalVar1=100;

Exe, DLL,

CodePudding user response:

reference 5 floor schlafenhamster reply:
LONG test_dllGlobalVar1=100;

Exe, DLL,

Hello, to be told about it? Best post code, the debate was I too long about

CodePudding user response:

reference 5 floor schlafenhamster reply:
LONG test_dllGlobalVar1=100;

Exe, DLL,


Still no test on my side, you can post your code? Thank you, I feel VS too difficult people, a global variable Shared, unexpectedly the so many VS,

CodePudding user response:

I don't know this line not line
 # pragma data_seg (" mydata ") 
HWND glhPrevTarWnd=NULL;//the window handle of the referred to in the last time the mouse
HWND glhDisplayWnd=NULL;//title edit box shows the target window handle
HHOOK glhHook=NULL;//install the mouse hook handle
HINSTANCE glhInstance=NULL;//DLL instance handle
BOOL gbIsWinDown=FALSE;
BOOL gbWinFlag=FALSE;
# pragma data_seg ()
# pragma comment (would, "/section: mydata, RWS")

CodePudding user response:

http://blog.163.com/wangpf2008@126/blog/static/3515511920077765318482/
  • Related