DLL호출 시 문자열 질문....
글쓴이: pat8002 / 작성시간: 수, 2009/09/02 - 2:19오후
자바만 해온지라 C++에 대해서는 잘 모르겠습니다..
하나씩 공부하고 있는데 어렵네요..ㅡㅡ;
DLL만들어서 호출하고 싶은데 int형은 잘 되는거 같은데
char형이 잘 안되서 질문드립니다..
**************************
dll에는
EXPORT char *test();
EXPORT char *test(){
return "Hello World";
}
로 했습니다..
**************************
**************************
dll호출하는 곳에선
typedef char(*test);
int main(){
test ftest;
ftest = (test)GetProcAddress(hinstance, "test");
printf("%s\n", ftest);
}
**************************
여기까진 했는데 "Hello World"를 찍고 싶은데 문자가 깨지는 건지.. 머가 잘못된 건지 제대로 안나옵니다..
어떤 식으로 해야 하나요?
너무 나무라하지 마시고 조언 부탁드립니다.;;;;
Forums:
printf("%s\n",
printf("%s\n", ftest());
이렇게 해야하지 않을까요?
-------------------------------------------------------------------------------
It's better to appear stupid and ask question than to be silent and remain stupid.
-------------------------------------------------------------------------------
It's better to appear stupid and ask question than to be silent and remain stupid.
load
원글님께선 LoadLibrary()도 빼먹은거 같은데요.
감사합니다...ftest()
댓글 감사합니다...
ftest() 하면 에러가.
int, bool은 되는데.
LoadLibrary 했습니다..^^;
많이 배우고 싶다~!!!나도 유식해 지자....
어떤 에러가
어떤 에러가 나나요?
-------------------------------------------------------------------------------
It's better to appear stupid and ask question than to be silent and remain stupid.
-------------------------------------------------------------------------------
It's better to appear stupid and ask question than to be silent and remain stupid.
c2064 term does not evaluate
c2064 term does not evaluate to a function taking 0 arguments
이거요.
많이 배우고 싶다~!!!나도 유식해 지자....
...
char* 에 () 붙여 봐야 뭐하겠습니까..
에러일 뿐...
보이는 문제점이
일단 위 예제상에서는 없어지는 지역변수의 주소를 포인터로 반환하고 있네요.
또
부분을
식으로 바꿔야 할 거 같네요. 위의 것을 굳이 해석하자면 char형데이터(문자 한개) 반환하는 함수의 포인터입니다.
추가 : DLL에서 malloc()했다면 DLL에서 free()해야 합니다. 예전에 회사에서 이거 모르고 만들었다가 대박 낭패 봤다는 -_-;
Written By the Black Knight of Destruction
Written By the Black Knight of Destruction
조언
조언 감사드립니다.
해결 했습니다.
type char*(*test)();
・
・
・
printf("%s\n", ftest());
간단한거 같으면서도 헷갈리네요..
감사합니다.
많이 배우고 싶다~!!!나도 유식해 지자....
댓글 달기