나는 code :: Blocks로 oop C++에서 작업하고 있습니다.객체 지향 프로그래밍 C++ dll 코드 :: 블록
마이크로 프로세서를 위해 C로 프로그램을 작성하기 때문에 이것들이 내 첫 걸음입니다.
dll을 연결하는 데 문제가 있습니다.
dll을 프로젝트에서 내 주요
입니다 : 당신이 볼 수있는#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
#include "xclass.h"
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
기본 재료 :
#include "main.h"
#include "xclass.h"
// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
이
은 헤더입니다.#ifndef XCLASS_H
#define XCLASS_H
class xclass
{
public:
xclass();
virtual ~xclass();
unsigned int GetCounter() { return m_Counter; }
void SetCounter(unsigned int val) { m_Counter = val; }
protected:
private:
unsigned int m_Counter;
};
#endif // XCLASS_H
내가 다른 프로젝트에서 DLL을 연결하고 사용 할 수 있었다
#include "xclass.h"
xclass::xclass()
{
//ctor
}
xclass::~xclass()
{
//dtor
}
와 헤더 :
문제
내가 일 주와 클래스 xclass을 포함하고 있다는 점이다. A는 심지어 DLLSomeFunction("teste x");
의 기능을 사용할 수 있습니다하지만 우리에게 클래스에 액세스 할 수 없습니다
#include <iostream>
#include "main.h"
//#include "../cvWrapper/main.h"
using namespace std;
int main()
{
xclass ClassInDll;// not working
SomeFunction("teste x"); //using the function in dll
printf("%d\n", 1);
return 0;
}
빌드 오류는 다음과 같습니다
|| === testDLL, 디버그 === | obj \ Debug \ main.o || 함수
main':| C:\Users\SoftVision\Desktop\PrinterCode\DLL_test\testDLL\main.cpp|9|undefined reference to
xclass :: xclass() '| C : \ Users \ SoftVision \ Desktop \ PrinterCode \ DLL_test \ testDLL \ main.cpp | undefinedxclass::~xclass()'| C:\Users\SoftVision\Desktop\PrinterCode\DLL_test\testDLL\main.cpp|14|undefined reference to
에 대한 참조 xclass :: ~ xclass() '| || === 빌드 완료 : 3 개의 오류, 0 경고 === | 도움을
감사합니다 ...
매크로는 무엇입니까? 윈프리? DLL 가드 포함? – harper