我的C代码中有LPCWSTR错误 [英] LPCWSTR error i have in my C code
问题描述
我写了一个调用mytest函数的代码,dll
这个函数返回字符s 。
这是我的代码:
#include< stdio.h>
#include< windows。 h>
int main(){
HANDLE ldll;
char(* str)(void) ;
ldll = LoadLibrary(" mytest.dll");
str = GetProcAddress(ldll," str" ;);
printf(" result:%c",str);
}
我得到这个错误:
警告C4133:''function'':不兼容的类型 - 从''char [11]''到''LPCWSTR''
警告C4047:''function'':'''LPCSTR''间接级别与''char(__ cdecl *)(void)''不同
警告C4024:''GetProcAddress'':正式和实际参数2的不同类型
错误C2440:''='':无法转换''FARPROC'' to''char(__ cdecl *)(void)''
p租约帮助我,
thx in advanced。
i wrote a c code which calls a function from mytest,dll
this function returns the character "s" .
this is my code :
#include<stdio.h>
#include<windows.h>
int main(){
HANDLE ldll;
char (*str)(void);
ldll = LoadLibrary("mytest.dll");
str = GetProcAddress(ldll, "str");
printf("result : %c", str);
}
and i get this errors :
warning C4133: ''function'' : incompatible types - from ''char [11]'' to ''LPCWSTR''
warning C4047: ''function'' : ''LPCSTR'' differs in levels of indirection from ''char (__cdecl *)(void)''
warning C4024: ''GetProcAddress'' : different types for formal and actual parameter 2
error C2440: ''='' : cannot convert from ''FARPROC'' to ''char (__cdecl *)(void)''
please help me ,
thx in advanced.
推荐答案
我想<一个rel =nofollowhref =http://msdn.microsoft.com/en-us/library/ms683212(VS.85).aspx\"target =_ blank>这个将对你有帮助。
谢谢
Raghu
Hi,
I think this will help you.
Thanks
Raghu
尝试以下方法。执行以下转换并查看它是否有效。您应该将farproc转换为char( __cdecl *)(无效)。
希望它有所帮助。
#include< stdio.h>
#include< windows.h>
int main(){
HANDLE ldll;
typedef char( * str)(void);
str str;
ldll = LoadLibrary(" mytest.dll");
Str =(str)GetProcAddress(ldll," str");
printf(" result:%c",str);
}
Try the following.Perform the following casting and see if it works.You should cast the farproc to char (__cdecl *)(void).
Hope it helps.
#include<stdio.h>
#include<windows.h>
int main(){
HANDLE ldll;
typedef char (*str)(void);
str Str;
ldll = LoadLibrary("mytest.dll");
Str = (str)GetProcAddress(ldll, "str");
printf("result : %c", str);
}
好的,现在我可以看到控制台上写着:
结果:(我无法做到之前,没有显示控制台)
但我的角色不在那里。我做了你告诉我的事,但我在我的dll中得到了这个错误:
错误C2059:语法错误:'')''
错误C2143:语法错误:在''{''
$ b $之前缺少'';'' b错误C2447:''{'':缺少函数头(旧式正式列表?)
错误在函数减速线中的mytest.cpp代码中:
EXPORT char(__ cdecl *)(void)
这是我的代码:
>
#include" mytest.h"
EXPORT char(__ cdecl *)(void){
char x =''s'';
返回x;
}
BOOL WINAPI DllMain(HANDLE hModule,DWORD dwReason,LPVOID lpReserved){
返回TRUE;
}
ok ,now i can see the console with this written on :
result : (i couldn''t see it before, no console was shown)
but my character is not there .I have done what you told me but i get this error in my dll :
error C2059: syntax error : '')''
error C2143: syntax error : missing '';'' before ''{''
error C2447: ''{'' : missing function header (old-style formal list?)
the error is in mytest.cpp code in the function deceleration line :
EXPORT char (__cdecl *)(void)
this is my code :
#include "mytest.h"
EXPORT char (__cdecl *)(void){
char x=''s'';
return x;
}
BOOL WINAPI DllMain(HANDLE hModule,DWORD dwReason,LPVOID lpReserved){
return TRUE;
}
这篇关于我的C代码中有LPCWSTR错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!