DLL호출 시 문자열 질문....

pat8002의 이미지

자바만 해온지라 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"를 찍고 싶은데 문자가 깨지는 건지.. 머가 잘못된 건지 제대로 안나옵니다..
어떤 식으로 해야 하나요?
너무 나무라하지 마시고 조언 부탁드립니다.;;;;

chadr의 이미지

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.

drinkme의 이미지

원글님께선 LoadLibrary()도 빼먹은거 같은데요.

pat8002의 이미지

댓글 감사합니다...

ftest() 하면 에러가.
int, bool은 되는데.

LoadLibrary 했습니다..^^;

많이 배우고 싶다~!!!나도 유식해 지자....

chadr의 이미지

어떤 에러가 나나요?
-------------------------------------------------------------------------------
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.

pat8002의 이미지

c2064 term does not evaluate to a function taking 0 arguments
이거요.

많이 배우고 싶다~!!!나도 유식해 지자....

아메스트리에우려먹은사골맹탕의 이미지

char* 에 () 붙여 봐야 뭐하겠습니까..
에러일 뿐...

Necromancer의 이미지

일단 위 예제상에서는 없어지는 지역변수의 주소를 포인터로 반환하고 있네요.

typedef char(*test);

부분을

typedef (char *)(*test)();

식으로 바꿔야 할 거 같네요. 위의 것을 굳이 해석하자면 char형데이터(문자 한개) 반환하는 함수의 포인터입니다.

추가 : DLL에서 malloc()했다면 DLL에서 free()해야 합니다. 예전에 회사에서 이거 모르고 만들었다가 대박 낭패 봤다는 -_-;

Written By the Black Knight of Destruction

Written By the Black Knight of Destruction

pat8002의 이미지

조언 감사드립니다.
해결 했습니다.

type char*(*test)();



printf("%s\n", ftest());

간단한거 같으면서도 헷갈리네요..

감사합니다.

많이 배우고 싶다~!!!나도 유식해 지자....

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.