본문 바로가기
Application/C#.net

C++ dll 을 C# 에서 사용하기

by 현이빈이 2010. 11. 11.
반응형


C++ 로 구현된 dll 사용시 포인터 사용시 C# 에서는 배열로 처리하면 된다.
또 dll 에서 포인터로 데이타를 다시 리턴 받는 경우에도 유용하다.

아래 함수의 경우 파일을 해당 사이즈 별로 저장하고 그 저장된 결과값을 다시 리턴해 준다.


C++ 원형

extern "C" C_TEST_API BOOL WINAPI open_file(const char* filename, const char* filename2, int size, int compress, int dpi, float* scr_width, float* src_height, int* dst_width, int* dst_height);



C# 사용

선언부

private static extern int open_file(char[] filename, char[] filename2, int size, int compress, int dpi, float[] src_width, float[] src_height, int[] dst_width, int[] dst_height);


구현부

float[] pdf_width = new float[1];
float[] pdf_height = new float[1];

int[] img_height = new int[1];
int[] img_width = new int[1];

int rtn = open_file(textBox1.Text.ToCharArray(), textBox2.Text.ToCharArray(), 500, 90, 150, pdf_width, pdf_height, img_width, img_height);


반응형