簡體   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