繁体   English   中英

链接.h .lib和.dll

[英]Linking .h .lib and .dll

我必须将项目链接到将用于其他应用程序的dll。 我的项目必须从dll中读取结构,更改其变量的某些值,然后将结构返回给dll。

这是我的.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;
}

这是我的.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

我已将DBase.lib添加到配置属性| 链接器| 输入| 附加依赖项和dll目录到“配置属性” | VC ++目录| 图书馆目录

我的问题是,我用另一个应用程序修改了IHMI [1]的值,然后当我使用此程序读取它时,我读取了未初始化的值(0)。

有什么建议吗? dll和程序是否正确喜欢?

注意:dll与项目位于不同的文件夹中。 其他文件(.ccp,.h和.lib)位于项目文件夹旁边的同一文件夹中。

注意2:我正在使用MVS2013-C ++ Win32控制台应用程序

非常感谢你!

谢谢大家! 我想我已经解决了这个问题。 我已将dll路径添加到“配置属性”中。 调试| 环境PATH = C:\\ where \\ is_the \\ dll;%PATH%我确定我正在使用程序和应用程序编写和读取相同的结构。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM