에러가 발생한다고 하시는데
어떤 에러가 뜬다는 얘기는 없으니 답변드릴수 있는 사람 이 없을겁니다.
그냥 에러라고 하면 컴파일 에러인지 RunTime시에 MIL 라이브러리에서 뜨는 에러인지 알길이 없죠
그리고 지난번에는 ActiveMIL OCX를 임포트 해서 사용하신다고 하였는데
이번에는 MIL 라이브러리 (dll)를 임포트가 아니고.
DLL를 동적 로딩(LoadLibrary) 해서 사용하시네요?
보통 dll에서 implib.exe 유틸로 임포트 라이브러리 만들어서 사용합니다.
동적 로딩이 잘못되었다는것은 아니고요 . 굳이 그렇게 어렵게 쓰는거 보다는 임포트 라이브러리 만들어서
헤더만 포함해서 쓰는게 편하다는 얘깁니다.
어쨌든 가물가물한 기억을 더듬으면 저는 그렇게 해서 문제없이 잘 사용했었습니다.
물론 몇년전이고 MIL 7.0 으로 했었고요.
일단 에러가 뜨는 부분이 어떤 내용의 에러인지 잘 보고 판단해 보시고
소스를 보니 함수들의 리턴값(에러) 체크가 전혀 안되어 있는것 같습니다.
각각의 함수 호출후 결과가 제대로 나왔는지 체크 바랍니다.
물론 컴파일 에러 말씀하시는거라면 다른 얘기겠지요
아래 소스는 수년전에 MIL 7.0으로 작업할때 쓰던 초기화 함수 입니다.
님이 사용하려는 기능과 차이가 있어 도움은 안되겠지만 참고만하세요
bool MilInit(void)
{
// 1, 2호기일 경우
if( F_HP->E_MachineNumber->GetInt() <= 2 )
{
IMAGE_WIDTH = 640;
IMAGE_HEIGHT = 480;
}
else
{
IMAGE_WIDTH = 768;
IMAGE_HEIGHT = 576;
}
if (MilApp == M_NULL)
{
MappAlloc(M_DEFAULT , &MilApp);
if (MilApp==M_NULL)
{
XfShowMsg("MilApplication Alloc Error", XT_ALARM);
return false;
}
XfLogMsg("VISION : MilApp Success");
//MappControl(M_ERROR, M_PRINT_DISABLE);
}
if ( MilSys == M_NULL)
{
// 디버깅 일대는 VGA모드로 초기화
if(XfIsCBuilderRunning()==false)
MsysAlloc(M_SYSTEM_METEOR_II , M_DEFAULT, M_COMPLETE, &MilSys);
else
MsysAlloc(M_SYSTEM_HOST , M_DEFAULT, M_COMPLETE, &MilSys);
if( MilSys == M_NULL)
{
XfShowMsg("MilSys Alloc Error - Align Camera", XT_ALARM);
return false;
}
//MsysControl(MilSys, M_STOP_LIVE_GRAB_WHEN_DISABLED, M_ENABLE);
XfLogMsg("VISION : MilSys Success");
}
if (MilImg1==M_NULL)
{
if(XfIsCBuilderRunning()==false)
MbufAlloc2d(MilSys, IMAGE_WIDTH, IMAGE_HEIGHT, 8 ,M_IMAGE+M_PROC+M_DISP+M_GRAB, &MilImg1);
else
MbufAlloc2d(MilSys, IMAGE_WIDTH, IMAGE_HEIGHT, 8 ,M_IMAGE+M_PROC+M_DISP, &MilImg1);
if (MilImg1==M_NULL)
{
XfShowMsg("MilImg Alloc Error - Align Image 1", XT_ALARM);
return false;
}
MbufClear(MilImg1, 0);
XfLogMsg("VISION : MilImg Success");
}
if (MilImg2==M_NULL)
{
if(XfIsCBuilderRunning()==false)
MbufAlloc2d(MilSys, IMAGE_WIDTH, IMAGE_HEIGHT, 8 ,M_IMAGE+M_PROC+M_DISP+M_GRAB, &MilImg2);
else
MbufAlloc2d(MilSys, IMAGE_WIDTH, IMAGE_HEIGHT, 8 ,M_IMAGE+M_PROC+M_DISP, &MilImg2);
if (MilImg2==M_NULL)
{
XfShowMsg("MilImg Alloc Error - Align Image 2", XT_ALARM);
return false;
}
MbufClear(MilImg2, 0);
XfLogMsg("VISION : MilImg Success");
}
if (MilImg1Color==M_NULL)
{
MbufAllocColor(MilSys, 3L, IMAGE_WIDTH, IMAGE_HEIGHT, 8+M_UNSIGNED ,M_IMAGE+M_PROC+M_DISP, &MilImg1Color);
if (MilImg1Color==M_NULL)
{
XfShowMsg("MilImg1Color Alloc Error - Align Image", XT_ALARM);
return false;
}
MbufClear(MilImg1Color, 0);
XfLogMsg("VISION : MilImg1Color Success");
}
if (MilImg2Color==M_NULL)
{
MbufAllocColor(MilSys, 3L, IMAGE_WIDTH, IMAGE_HEIGHT, 8+M_UNSIGNED ,M_IMAGE+M_PROC+M_DISP, &MilImg2Color);
if (MilImg2Color==M_NULL)
{
XfShowMsg("MilImg2Color Alloc Error - Align Image", XT_ALARM);
return false;
}
MbufClear(MilImg2Color, 0);
XfLogMsg("VISION : MilImg2Color Success");
}
if (MilImgProc==M_NULL)
{
MbufAlloc2d(MilSys, IMAGE_WIDTH, IMAGE_HEIGHT, 8 ,M_IMAGE+M_PROC+M_DISP, &MilImgProc);
// MbufAllocColor(MilSys, 3L, IMAGE_WIDTH, IMAGE_HEIGHT, 8+M_UNSIGNED ,M_IMAGE+M_PROC+M_DISP, &MilImgProc);
if (MilImgProc==M_NULL)
{
XfShowMsg("MilImgProc Alloc Error - Align Image", XT_ALARM);
return false;
}
MbufClear(MilImgProc, 0);
XfLogMsg("VISION : MilImgProc Success");
}
//----------------------------------------------------------------------------
if (MilDis1==M_NULL )
{
MdispAlloc(MilSys, M_DEFAULT, M_DISPLAY_SETUP, M_WINDOWED, &MilDis1);
if (MilDis1==M_NULL)
{
XfShowMsg("MilDis Alloc Error - Align Display 1", XT_ALARM);
return false;
}
XfLogMsg("VISION : MilDis Success");
}
MdispZoom(MilDis1, -2, -2);
SelectImage(MilDis1, MilImg1, F_Run->P_Vs1);
MdispControl(MilDis1, M_WINDOW_UPDATE_ON_PAINT, M_ENABLE);
// XfLogPrintf("VS Handle = %d ", F_Run->P_Vs1->Handle);
//---------------------------------------------------------------------------
if (MilDis2==M_NULL )
{
MdispAlloc(MilSys, M_DEFAULT, M_DISPLAY_SETUP, M_WINDOWED, &MilDis2);
if (MilDis2==M_NULL)
{
XfShowMsg("MilDis Alloc Error - Align Display 2", XT_ALARM);
return false;
}
XfLogMsg("VISION : MilDis Success");
}
MdispZoom(MilDis2, -2, -2);
SelectImage(MilDis2, MilImg2, F_Run->P_Vs2);
MdispControl(MilDis2, M_WINDOW_UPDATE_ON_PAINT, M_ENABLE);
//----------------------------------------------------------------------------
if( MilImg1Ovr == M_NULL)
{
/* Prepare overlay buffer. */
/***************************/
/* Disable overlay display while preparing the data. */
MdispControl(MilDis1, M_WINDOW_OVR_SHOW, M_DISABLE);
/* Enable writing Overlay graphics on top of display buffer. */
MdispControl(MilDis1, M_WINDOW_OVR_WRITE, M_ENABLE);
/* Inquire the Overlay buffer associated with the displayed buffer. */
MdispInquire(MilDis1, M_WINDOW_OVR_BUF_ID, &MilImg1Ovr);
if (MilImg1Ovr==M_NULL)
{
XfLogMsg("MilImgOvr 1 Alloc Error");
XfShowMsg("MilImgOvr 1 Alloc Error", XT_ALARM);
}
else
{
/* Inquire the current keying color. */
MdispInquire(MilDis1, M_KEY_COLOR, &MilTransparentColor);
/* Clear the overlay buffer with the keying color. */
MbufClear(MilImg1Ovr, MilTransparentColor);
/* Enable the overlay display. */
MdispControl(MilDis1, M_WINDOW_OVR_SHOW, M_ENABLE);
/* Set graphic text to transparent background. */
MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT);
/* Set drawing color to white. */
MgraColor(M_DEFAULT, 255);
XfLogMsg("OverLay Image 1 초기화 성공");
}
}
if( MilImg2Ovr == M_NULL)
{
/* Prepare overlay buffer. */
/***************************/
/* Disable overlay display while preparing the data. */
MdispControl(MilDis2, M_WINDOW_OVR_SHOW, M_DISABLE);
/* Enable writing Overlay graphics on top of display buffer. */
MdispControl(MilDis2, M_WINDOW_OVR_WRITE, M_ENABLE);
/* Inquire the Overlay buffer associated with the displayed buffer. */
MdispInquire(MilDis2, M_WINDOW_OVR_BUF_ID, &MilImg2Ovr);
if (MilImg2Ovr == M_NULL)
{
XfLogMsg("MilImgOvr 2 Alloc Error");
XfShowMsg("MilImgOvr 2 Alloc Error", XT_ALARM);
}
else
{
/* Inquire the current keying color. */
MdispInquire(MilDis2, M_KEY_COLOR, &MilTransparentColor);
/* Clear the overlay buffer with the keying color. */
MbufClear(MilImg2Ovr, MilTransparentColor);
/* Enable the overlay display. */
MdispControl(MilDis2, M_WINDOW_OVR_SHOW, M_ENABLE);
/* Set graphic text to transparent background. */
MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT);
/* Set drawing color to white. */
MgraColor(M_DEFAULT, 255);
XfLogMsg("OverLay Image 2 초기화 성공");
}
}
//----------------------------------------------------------------------------
// Digitizer를 제일 나중에 초기화
// CBuilder를 실행중일때는 초기화 안함 -> 디버깅용
if( MilDig==M_NULL && XfIsCBuilderRunning()==false)
{
// 1, 2호기일 경우
if( F_HP->E_MachineNumber->GetInt() <= 2 )
{
XfLogMsg("1,2호기 Vision 카메라 CCIR 설정" );
MdigAlloc(MilSys, M_DEV0, "M_CCIR", M_DEFAULT, &MilDig);
}
else
{
XfLogMsg("3,4호기이후 Vision 카메라 RS-170 설정" );
MdigAlloc(MilSys, M_DEV0, "M_RS170", M_DEFAULT, &MilDig);
}
if(MilDig==M_NULL)
{
XfShowMsg("MilDig Alloc Error - Align Camera", XT_ALARM);
return false;
}
XfLogMsg("VISION : MilDig Success");
if( F_HP->CB_UseCamLock->XChecked )
{
MdigControl(MilDig , M_CAMERA_LOCK , M_ENABLE + M_FAST);
}
// MdigControl(MilDig , M_CAMERA_PRESENT_SENSITIVITY , F_HP->E_CmrLock->GetInt());
}
XfLogMsg("Vision Mil 초기화 성공");
if(XfIsCBuilderRunning()==true)
{
AnsiString file = ExtractFilePath(Application->ExeName) + "mark.mim";
MbufLoad(file.c_str(), MilImg1);
MbufLoad(file.c_str(), MilImg2);
}
bVsInitOk = true;
DrawCross(MilImg1Ovr, -2, 0L);
DrawCross(MilImg2Ovr, -2, 0L);
return true;
}
이용희 님이 쓰신 글 :
: matrox lite 8.0을 사용하는 중인데..
:
: dll을 import 해서 사용합니다...
: 문자열 인자로 주는데서 계속 에러가 납니다..
:
: 그 부분을 MsysAlloc과 MdigAlloc에서
: 포인터로 문자열을 인자로 줄때 에러가 납니다..
:
: 고수님께 정중희 부탁드립니다..
:
: 헤멘지 벌써 10일이 지났습니다...
:
: //
: TfrmImg *frmImg;
: /*
: //카메라 또는 디지타이저 세팅
: typedef MIL_ID __stdcall __declspec(dllimport)Func_MappAlloc(long InitFlag,MIL_ID *ApplicationIdPtr);
: typedef MIL_ID __stdcall __declspec(dllimport)Func_MsysAlloc(MIL_TEXT_PTR SystemDescriptor,long SystemNum,long InitFlag,MIL_ID *SystemIdPtr);
: typedef MIL_ID __stdcall __declspec(dllimport)Func_MdigAlloc(MIL_ID SystemId,long DigNum,MIL_TEXT_PTR DataFormat,long InitFlag,MIL_ID *DigIdPtr);
: typedef MIL_ID __stdcall __declspec(dllimport)Func_MbufAlloc2d(MIL_ID SystemId,long SizeX,long SizeY,long Type,MIL_INT64 Attribute,MIL_ID *BufIdPtr);
: typedef void __stdcall __declspec(dllimport)Func_MbufClear(MIL_ID DestImageBufId,double Color);
: typedef void __stdcall __declspec(dllimport)Func_MdigControl(MIL_ID DigId,long ControlType,double ControlValue);
: //이미지 그랩
: typedef void __stdcall __declspec(dllimport)Func_MdigGrab(MIL_ID DigId,MIL_ID DestImageBufId);
: typedef long __stdcall __declspec(dllimport)Func_MbufInquire(MIL_ID BufId,long InquireType,void *UserVarPtr);
: //카메라 및 메모리 해제
: typedef void __stdcall __declspec(dllimport)Func_MbufFree(MIL_ID BufId);
: typedef void __stdcall __declspec(dllimport)Func_MdigFree(MIL_ID DigId);
: typedef void __stdcall __declspec(dllimport)Func_MsysFree(MIL_ID SystemId);
: typedef void __stdcall __declspec(dllimport)Func_MappFree(MIL_ID ApplicationId);
:
: Func_MappAlloc *MappAlloc;
: Func_MsysAlloc *MsysAlloc;
: Func_MdigAlloc *MdigAlloc;
: Func_MbufAlloc2d *MbufAlloc2d;
: Func_MbufClear *MbufClear;
: Func_MdigControl *MdigControl;
: Func_MdigGrab *MdigGrab;
: Func_MbufInquire *MbufInquire;
: Func_MbufFree *MbufFree;
: Func_MdigFree *MdigFree;
: Func_MsysFree *MsysFree;
: Func_MappFree *MappFree;
:
: //---------------------------------------------------------------------------
: __fastcall TfrmImg::TfrmImg(TComponent* Owner)
: : TForm(Owner)
: {
: }
:
: void __fastcall TfrmImg::InitModule()
: {
: hiInstance = LoadLibrary("mil.dll");
:
: MappAlloc = (Func_MappAlloc *)GetProcAddress(hiInstance, "MappAlloc");
: MsysAlloc = (Func_MsysAlloc *)GetProcAddress(hiInstance, "MsysAlloc");
: MdigAlloc = (Func_MdigAlloc *)GetProcAddress(hiInstance, "MdigAlloc");
: MbufAlloc2d = (Func_MbufAlloc2d *)GetProcAddress(hiInstance, "MbufAlloc2d");
: MbufClear = (Func_MbufClear *)GetProcAddress(hiInstance, "MbufClear");
: MdigControl = (Func_MdigControl *)GetProcAddress(hiInstance, "MdigControl");
: MbufInquire = (Func_MbufInquire *)GetProcAddress(hiInstance, "MbufInquire");
: MbufFree = (Func_MbufFree *)GetProcAddress(hiInstance, "MbufFree");
: MdigFree = (Func_MdigFree *)GetProcAddress(hiInstance, "MdigFree");
: MsysFree = (Func_MdigFree *)GetProcAddress(hiInstance, "MsysFree");
: MappFree = (Func_MappFree *)GetProcAddress(hiInstance, "MappFree");
:
: }
: //---------------------------------------------------------------------------
:
: //---------------------------------------------------------------------------
:
:
: //---------------------------------------------------------------------------
:
:
: void __fastcall TfrmImg::FormCreate(TObject *Sender)
: {
: InitModule();
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TfrmImg::FormClose(TObject *Sender, TCloseAction &Action)
: {
: FreeLibrary(hiInstance);
: }
: //---------------------------------------------------------------------------
:
:
:
: void __fastcall TfrmImg::btnInitClick(TObject *Sender)
: {
:
:
:
: MappAlloc(M_DEFAULT,&MilApplication);
: MsysAlloc(M_SYSTEM_SOLIOS,M_DEFAULT,M_DEFAULT,&MilSystem);
: MdigAlloc(MilSystem,M_DEV0,milDcf,M_DEFAULT,&MilDigitizer);
: MbufAlloc2d(MilSystem,width,height,16+M_UNSIGNED,M_IMAGE+M_GRAB,&MilImage);
: MbufClear(MilImage,0xff);
: MdigControl(MilDigitizer,M_GRAB_MODE,M_ASYNCHRONOUS);
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TfrmImg::btnGrabClick(TObject *Sender)
: {
: MdigGrab(MilDigitizer,MilImage);
: MbufInquire(MilImage,M_HOST_ADDRESS,&pImg);
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TfrmImg::btnFreeClick(TObject *Sender)
: {
: MbufFree(MilImage);
: MdigFree(MilDigitizer);
: MsysFree(MilSystem);
: MappFree(MilApplication);
: }
: ///
: 그런데
: MsysAlloc(M_SYSTEM_SOLIOS,M_DEFAULT,M_DEFAULT,&MilSystem);
: MdigAlloc(MilSystem,M_DEV0,milDcf,M_DEFAULT,&MilDigitizer);
: 에러가 납니다..
: MIL_TEXT_PTR 는 mil.h에서 보면
: char *로 선언 되어 있습니다.
:
: 왜 애러가 나는지
: 어떻게 해결하셨는지
: 한수 부탁드립니다...