Template

2019. 8. 5. 18:02

보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

C#에서 Delphi DLL을 호출하기


아래 주소에서 Convertion Data Type을 확인할 수 있다.

http://netcoole.com/delphi2cs/datatype.htm


우선 Delphi DLL 에서 호출할 함수의 형태를 파악한다.

ex )

TestDll.dll

function DllTest(Content : string, pData : pointer, Length : integer) : boolean ; stdcall;

var

...

begin

...

end;


의 형태라 가정하면



C#에서는 다음과 같이 정의를 해주어야 한다.

[DllImport("TestDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]

public static extern bool DllTest(string Content, byte[] pData, int Length);


혹은 내부 구현에 따라서 다음과 같다.

[DllImport("TestDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]

public static extern bool DllTest(string Content, object pData, int Length);


☆ CallingConvention 및 CharSet은 해당하는 값으로 변경하여 사용하도록 한다.


그 후 기존의 함수를 호출하듯 사용해주면 된다.

Posted by altDeveloper
,

MessageBox 사용법

MFC 2015. 7. 9. 10:02

MFC의 MessageBox 함수의 사용법!!



MessageBox 함수의 리턴값은 다음과 같다.

#define IDOK                1
#define IDCANCEL            2
#define IDABORT             3
#define IDRETRY             4
#define IDIGNORE            5
#define IDYES               6
#define IDNO                7


MessageBox( 출력할 문자열, 메시지박스 제목, 메시지 박스의 종류 )


메시지 박스의 종류는 다음과 같다.

/*
 * MessageBox() Flags
 */
#define MB_OK                       0x00000000L
#define MB_OKCANCEL                 0x00000001L
#define MB_ABORTRETRYIGNORE         0x00000002L
#define MB_YESNOCANCEL              0x00000003L
#define MB_YESNO                    0x00000004L
#define MB_RETRYCANCEL              0x00000005L
#if(WINVER >= 0x0500)
#define MB_CANCELTRYCONTINUE        0x00000006L


사용방법은 아래의 예시를 참고


// OK를 눌렀을 경우 if문

if ( MessageBox("테스트용 메시지 박스입니다", "메시지창", MB_OKCANCEL) == IDOK )

// cancel을 눌렀을 경우 else문을 실행. 함수의 리턴값은 IDCANCEL

else

...

Posted by altDeveloper
,