|
이해가 잘 안되네요
몇가지 체크해보세요
1. LoadLibrary 에서
m_hHandle = LoadLibrary(("C\\aaa.dll").c_str()); //이 아니라
m_hHandle = LoadLibrary("C\\aaa.dll"); // ==> 그냥 이렇게 하세요
2. FormShow에서
tempclass 클래스를 new하는 부분이 없네요
new로 생성하지 않고 tempclass->AFunc() 이렇게 그냥사용하시면
실제 tempclass의 인스턴스 객체는 생성되지않는상태에서 함수만 호출된것이되는데..
AFunc 함수내에서 인스턴스 맴버를 access하면 에러가 나겠죠
포인터로 선언한 놈은
TTempClass* tempclass=new TTempClass;
이렇게 생성한후에 함수를 쓰시고
마지막엔 delete tempclass; 이렇게 free하시구요
만약 new 하기 귀찮으시면
위와같이 쓰시면 자동 생성되었다가 FormShow함수가 끝날때 자동 free됩니다.
void __fastcall TForm1::FormShow(TObject *Sender)
{
TTempClass tempclass;
if (tempclass.AFunc())
{
}
if (tempclass.BFunc())
{
}
}
그럼...
짱구오빠 님이 쓰신 글 :
: 너무 초보적인 질문이라도 답변 부탁드립니다.
:
: 메인폼 하나와
: Unit 하나를 생성하고
: 아래와 같이 클래스를 선언했습니다.
:
: 유닛에 코딩한 함수입니다.
:
: #include "TempClass.h"
:
: //HINSTANCE m_hHandle;
:
: bool TTempClass ::AFunc(void)
: {
: //Library Load
: m_hHandle = LoadLibrary(("C\\aaa.dll").c_str());
: if (m_hHandle == NULL) return false;
:
: //Get Proc Address Set
: Initialize = (DWORD(__stdcall*)(void*))GetProcAddress(m_hHandle , "C_Initialize");
: }
:
: bool TTempClass ::BFunc(void)
: {
: }
:
: Unit 헤더파일에 아래와 같이 선언했습니다.
:
: #ifndef TempClassH
: #define TempClassH
:
: //Class Define
: class TTempClass
: {
: private:
: HINSTANCE m_hHandle;
:
: DWORD (WINAPI* Initialize)(void* m_pReserved);
:
: public:
: bool AFunc(void);
: bool BFunc(void);
: }
:
: 메인폼에 아래와 같이 선언했습니다.
:
: //HSM Library & Connect class
: TTempClass* tempclass;
:
: //---------------------------------------------------------------------------
: //Form Show Event
: //---------------------------------------------------------------------------
: void __fastcall Tfmainform::FormShow(TObject *Sender)
: {
: if (tempclass->AFunc())
: {
: }
:
: if (tempclass->BFunc())
: {
: }
:
: }
:
:
: 이렇게 컴파일해서 실행하니
: LoadLibrary 함수 처리할때 Exception 에러가 납니다.
:
: 또한
: GetProcAddress
: 부분에서도 Exception 에러가 나네요.
:
:
: HINSTANCE m_hHandle;
: 선언을 유닛에 선언하면 에러가 나질 않네요.
|