0

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!

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • The two applications will each have their own, separate, data area from the DLL. You need to explictyl mark the data as shared. – Roger Rowland Jan 14 '15 at 10:45
  • 1
    Everything is OK, but you don't understand how Dll works. There is no any relation between two instances of Dll running in different processes. You need to sane data in a file, or use inter-process communications. – Alex F Jan 14 '15 at 10:45
  • [Codeproject](http://www.codeproject.com/Articles/240/How-to-share-a-data-segment-in-a-DLL) has an example of data sharing, if that helps. However, there are plenty of gotchas with this approach and some form of IPC is preferred. – Roger Rowland Jan 14 '15 at 10:47
  • @Roger Rowland, you are totally right, it looks like I am modifying one struct using the c++ program and modifying another struct inside the same dll using the application. Thanks – Andres Torre Jan 14 '15 at 11:34

1 Answers1

0

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.