만나서 반가워요! 이것은 stacoverflow에 대한 첫 번째 게시물입니다. 저는 제 자신의 교육을 위해 C++과 LabVIEW를 공부하고 있습니다.C++로 LabVIEW에서 빌드 한 DLL을 호출하는 방법
LabVIEW는 그래픽 디자인 프로그래밍 환경이며 LabVIEW 코드에서 DLL을 빌드 할 수 있습니다. "LabVIEW 코드에서 DLL 만들기" https://decibel.ni.com/content/docs/DOC-15556
간단한 DLL을 만들고 C++ 코드에서 호출하려고했습니다. DLL에서 A와 B를 합할 수 있습니다. 먼저, 다음과 같이 소스 코드를 만들었습니다.
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
\t HINSTANCE hDLL = LoadLibrary(TEXT("C:\\sum_dll.dll"));
\t \t if(hDLL == NULL){
\t \t cout << "error" << endl;
\t }
\t
\t FARPROC lpIO = GetProcAddress(HMODULE(hDLL),"Sum_dll");
\t typedef int (*FUNC)(int a, int b);
\t FUNC myFunc;
\t myFunc = FUNC(lpIO);
\t int myValue = myFunc(2,32);
\t cout << myValue << endl;
\t FreeLibrary(hDLL);
\t return 0;
}
**************************** DLL header file ****************************
#include "extcode.h"
#pragma pack(push)
#pragma pack(1)
#ifdef __cplusplus
extern "C" {
#endif
/*!
* Sum_dll
*/
int32_t __cdecl Sum_dll(int32_t A, int32_t B);
MgErr __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
#ifdef __cplusplus
} // extern "C"
#endif
#pragma pack(pop)
*****************************************************************************
다음으로 dll 구성과 C++ 코드가 바뀌 었습니다.
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;
typedef int (*FUNC)(int, int,int *);
int _tmain(int argc, _TCHAR* argv[])
{
\t HINSTANCE hDLL = LoadLibrary(TEXT("C:\\sum_dll.dll"));
\t \t if(hDLL == NULL){
\t \t cout << "error" << endl;
\t }
\t
\t FARPROC lpIO = GetProcAddress(HMODULE(hDLL),"Sum_dll");
\t
\t FUNC myFunc;
\t myFunc = FUNC(lpIO);
\t
\t cout << myFunc(2,3,0) << endl;
\t //cout << "myValue = " << myValue << endl;
\t FreeLibrary(hDLL);
\t return 0;
}
**************************** DLL header file ****************************
#include "extcode.h"
#pragma pack(push)
#pragma pack(1)
#ifdef __cplusplus
extern "C" {
#endif
/*!
* Sum_dll
*/
void __cdecl Sum_dll(int32_t A, int32_t B, int32_t *C);
MgErr __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
#ifdef __cplusplus
} // extern "C"
#endif
#pragma pack(pop)
*****************************************************************************
내 코드에 문제가 있다고 생각하지만이 원인을 찾을 수 없습니다. 조언이 있으면 의견을 말하십시오.
감사합니다. 함수 서명이 일치하지 않는
: myFunc
세 번째 인수를 가정
로드 myValue' 당신이 가진 코드에서. 어떻게 0을 돌려 줄 수 있을까요? – PaulMcKenzie
두 번째 버전의 'myFunc'에서 세 번째 인수는 무엇을 의미합니까? 그게 합계가되어야합니까? – PaulMcKenzie