I have to link my project to a dll which will be used for another application. My project has to read a struct from the dll, change some values of its variables and return the struct to the dll.
This is my .ccp
#include "stdafx.h"
#include <iostream>
#include "dbase.h"
#pragma comment(lib, "DBase.lib")
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a;
cout << DBASE.IHMI[1] << "\n";
//DBASE.IHMI[1] = 22;
cin >> a;
return 0;
}
and this is my .h:
#ifndef DBASE_H
#define DBASE_H
typedef signed char L1;
typedef short int I2;
typedef int I4;
typedef float R4;
#pragma pack(1)
typedef struct _DBASESTRUT {.......} DBASESTRUT;
#pragma pack()
#ifdef __cplusplus
extern "C"{
#endif
__declspec(dllimport) extern DBASESTRUT DBASE;
#ifdef __cplusplus
}
#endif
#endif
I have added DBase.lib to Configuration Properties | Linker | Input | Additional Dependencies and the dll directory to Configuration Properties | VC++ Directories | Library Directories
My problem is that I modify the value of the IHMI[1] with the other application and then when I read it using this program, I read the no-initialised value (0).
any advise? are the dll and the program liked properly?
NOTE: the dll is in a different folder than the project. The other files (.ccp, .h and .lib) are in the same folder in side the project folder.
NOTE2: I am using MVS2013 - C++ Win32 console application
Thank you very much!
Thanks all! I think I have solved the issue. I have added the dll path to Configuration Properties | Debugging | Environment PATH=C:\\where\\is_the\\dll;%PATH% I am sure I am writing and reading the same struct using my program and the application.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.