请教关于.net 2003编译提示“char (*)与“char *”的间接级别不同” 警告的问题

qsxiaoyao 2007-11-12 09:14:49
#include <stdio.h>
#include <stdlib.h>

#ifdef WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#define __stdcall
#define LIB_NAME "./libMWGateway.so"
#endif

//////////////////////////////////////////////////////////////////////////
int (__stdcall *MongateConnect)(const char*, int, const char*, const char*);
void (__stdcall *MongateDisconnect)(int);
int (__stdcall *MongateTestConn)(int sock);
int (__stdcall *MongateCsSPSendSms)(int sock, const char* pszMobis, const char* pszMsg,
int iMobiCount,const char* pszSubPort,char* pszSN);
int (__stdcall *MongateCsGetSmsEx)(int sock, char strMsg[500][255]);
int (__stdcall *MongateCsGetStatusReportEx)(int sock, char *strMsg);
int (__stdcall *MGhexChrTosrcStr)(const char* srcMsg[255],char* retMsg[255]);
//////////////////////////////////////////////////////////////////////////
char* menu[] = {
"a - Send message", //发单向信息,单向网关接口使用
"b - Receive alarm message", //接收信息
"c - Receive status report",
"d - Test the connection",
"q - Quit",
NULL
};
//////////////////////////////////////////////////////////////////////////
int main(void)
{
int sock = 0;
int res = 0;
char selected = 0;
char **option = NULL;
void *handle = NULL;
char pszSN[500] = {0};
char strMsg[500][255] = {0};
char srcMsg[255] = {0};
char destMsg[255] = {0};
int i = 0;
printf("%s\n",pszSN);

#ifdef WIN32
handle = LoadLibrary("MWGateway.dll");
#else
handle = dlopen(LIB_NAME, RTLD_LAZY);
if (handle == NULL) {
printf("err: %s\n", dlerror());
puts("Program terminated!");
return 1;
}
#endif

#ifdef WIN32
MongateConnect = (void*)GetProcAddress(handle, "MongateConnect");
MongateCsSPSendSms = (void*)GetProcAddress(handle, "MongateCsSPSendSms");
MongateDisconnect = (void*)GetProcAddress(handle, "MongateDisconnect");
MongateTestConn = (void*)GetProcAddress(handle, "MongateTestConn");
MongateCsGetSmsEx = (void*)GetProcAddress(handle, "MongateCsGetSmsEx");
MongateCsGetStatusReportEx = (void*)GetProcAddress(handle, "MongateCsGetStatusReport");
MGhexChrTosrcStr = (void*)GetProcAddress(handle, "MGhexChrTosrcStr");
#else
MongateConnect = dlsym(handle, "MongateConnect");
MongateCsSPSendSms = dlsym(handle, "MongateCsSPSendSms");
MongateDisconnect = dlsym(handle, "MongateDisconnect");
MongateTestConn = dlsym(handle, "MongateTestConn");
MongateCsGetSmsEx = dlsym(handle, "MongateCsGetSmsEx");
MongateCsGetStatusReportEx = dlsym(handle, "MongateCsGetStatusReportEx");
MGhexChrTosrcStr = dlsym(handle, "MGhexChrTosrcStr");
#endif

puts("Waiting for connecting to the server......");
sock = MongateConnect("server1.montnets.com", 8018, "SZAEE", "362571");
if (sock < 1) {
printf("fail to connect to the server. Error Numbers is %d\n", sock);
return 1;
}

puts("connect to the server successfully!");
option = menu;
do {
while (*option) {
puts(*option);
option++;
}
printf("Please select an action:");
selected = getchar();
while (getchar() != '\n') ;//empty loop
switch (selected)
{
case 'a':
res = MongateCsSPSendSms(sock, "15989327101,13826559075", "English,中文", 2, "*", pszSN);
if ( res == 1) {
printf("报警 send success.SN is %s\n", pszSN);
} else {
printf("Send failed. Error Numbers is %d\n", res);
}
break;
case 'b':
res = MongateCsGetSmsEx(sock, srcMsg);
if (res == -1)
puts("Blank!");
else if (res == -101)
puts("Send time out!");
else if (res == -102)
puts("Send failed!");
else if (res == 0)
puts("There is 0 new sms.");
else if (res > 0) {
res = MGhexChrTosrcStr(srcMsg, destMsg);
for (i = 0; i < res; ++i) {
printf("%s\n", *destMsg);
}
}
break;
case 'c':
res = MongateCsGetStatusReportEx(sock, strMsg);
if (res == -1)
puts("Blank!");
else if (res == -101)
puts("Send time out!");
else if (res == -102)
puts("Send failed!");
else if (res == 0)
puts("There is 0 new sms.");
else
for (i = 0; i < res; ++i) {
printf("(%d): %s\n", i+1, strMsg[i]);
}
break;
case 'd':
res = MongateTestConn(sock);
if (res == 1)
printf("The connect is available!\n");
else if (res == -3)
printf("The connect is invalidation!\n");
else
printf("Connect time out!\n");
break;
case 'q':
puts("Good Bye! 再见!");
break;
default:
puts("Error choice! Or empty function. Please select again.");
break;
}
} while (selected != 'q');

if (sock)
MongateDisconnect(sock);
return 0;
}
...全文
628 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qsxiaoyao 2007-11-12
  • 打赏
  • 举报
回复
呵呵,找到原因了,
int (__stdcall *MongateCsGetSmsEx)(int sock, char strMsg[500][255]);
int (__stdcall *MongateCsGetStatusReportEx)(int sock, char *strMsg);
int (__stdcall *MGhexChrTosrcStr)(const char* srcMsg[255],char* retMsg[255]);
我竟然这样声明的函数,呵呵
qsxiaoyao 2007-11-12
  • 打赏
  • 举报
回复
刚查了下
WINBASEAPI FARPROC WINAPI GetProcAddress(IN HMODULE hModule, IN LPCSTR lpProcName);
typedef HINSTANCE HMODULE;
typedef void *HMODULE;
typedef void *HINSTANCE;

这里的handle应该是HMODULE型的,为void*,是我命名有问题。

第二个参数我实在不知道该怎么改。。。新各位朋友帮帮忙, 不胜感激
qsxiaoyao 2007-11-12
  • 打赏
  • 举报
回复
谢谢您,请问应该怎么改了?我试着改了这些参数,但还是一直这样提示错误,我太菜了,呵呵
dchilli 2007-11-12
  • 打赏
  • 举报
回复
GetProcAddress的第一个参数是HANDLE,你传入的是VOID*
MGhexChrTosrcStr的第二个参数是char*,你传入的是char[255]...
qsxiaoyao 2007-11-12
  • 打赏
  • 举报
回复
我是新手,实在找不出问题在哪里。是不是MWGateway.dll 和libMWGateway.so 里的函数原形参数定义有问题?
我得到的SDK说明里都是类似int __stdcall MGhexChrTosrcStr(const char* srcMsg,char* retMsg) 形式的参数传递。是不是说明文档和实际动态库中定义不符?还是我哪里弄错了?

还有个问题是在windows下程序执行后能顺利连接到服务器并成功发送短信到我的手机上,但在linux下连接服务器失败,返回的错误也有好几种。这个项目很简单,不想拖久了,请各位高手帮忙,不胜感激!
qsxiaoyao 2007-11-12
  • 打赏
  • 举报
回复
该程序在windows和linux下编译都会提示
note.c
d:\wangqs\software\task5\linux\note.c(103) : warning C4047: “函数” : “char (*)[255]”与“char [255]”的间接级别不同
d:\wangqs\software\task5\linux\note.c(113) : warning C4047: “函数” : “const char ** ”与“char [255]”的间接级别不同
d:\wangqs\software\task5\linux\note.c(113) : warning C4047: “函数” : “char ** ”与“char [255]”的间接级别不同
d:\wangqs\software\task5\linux\note.c(120) : warning C4047: “函数” : “char *”与“char [500][255]”的间接级别不同
正在链接...
LINK : warning LNK4075: 忽略“/EDITANDCONTINUE”(由于“/INCREMENTAL:NO”规范)

生成日志保存在“file://d:\wangqs\software\task5\linux\Debug\BuildLog.htm”中
note - 0 错误,5 警告

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧