您的位置:程序门 -> vc/mfc -> 进程/线程/dll



dll与exe传递空指针问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


dll与exe传递空指针问题[已结贴,结贴人:zszszs1983]
发表于:2007-05-11 09:31:00 楼主
我的dll中有函数:
extern   "c "   __declspec(dllexport)   xx*   jlda()
返回一个null的指针
但是在exe中当
xx*   a;
a   =   jlda();
if判断后a却不是null;为啥?
发表于:2007-05-11 09:35:241楼 得分:0
把jlda的代码贴出来
发表于:2007-05-11 09:36:452楼 得分:0
return   null;
没了,做个测试用用
发表于:2007-05-11 09:47:073楼 得分:50
没指定调用规则,看看这有没有影响。

另外,你可以在执行a   =   jlda();的时候断点查看调用的汇编,jlda()中应该有
mov   eax,   0
ret
或等效指令,
在call   jlda之后应该有
mov   [ebp+4],   eax   //返回值送a,[ebp+4]为局部变量a在栈中地址,可能会有不同如[ebp+8]等
看看此时eax是0吗
发表于:2007-05-11 09:54:384楼 得分:0
指定调用规则?能帮忙举个例子么?
发表于:2007-05-11 09:57:405楼 得分:0
__stdcall
发表于:2007-05-11 10:19:596楼 得分:0
问题我用__declspec来声明dll中的导出函数的
发表于:2007-05-11 10:20:597楼 得分:0
用__stdcall也可以么?
发表于:2007-05-11 16:11:078楼 得分:0
没回答的了么,顺道问问,dll怎么调试跟踪啊,断点怎么设啊?
发表于:2007-05-11 16:15:019楼 得分:5
调用约定也是需要的,再看看你反回的指针是否无效
发表于:2007-05-12 10:22:1310楼 得分:0
指针返回的不是null了,而是一个别的地址,如何判断好呢
发表于:2007-05-12 10:32:2611楼 得分:0
没遇见过这个问题,关注一下
发表于:2007-05-16 16:22:4312楼 得分:0
晕啊,100分啊,没人能回答了么,全部奉送啦
发表于:2007-05-16 16:46:4913楼 得分:0
我试了,可以返回null
发表于:2007-05-16 16:53:3614楼 得分:40
你可以试试:
dll文件:
头文件
#ifdef   test_h_h
#else
#define   test_h_h   extern   "c "   _declspec(dllimport)
#endif

test_h_h   int*   aa();
实现文件:
#define   test_h_h   extern   "c "   _declspec(dllexport)
#include   "666.h "
#include   <stdio.h>

int   *   aa()
{
return   null;
}

测试程序代码:
int   main(int   argc,   char*   argv[])
{
int   *   a;
int   m=0;
a=&m;
a=aa();
if(a==null)
cout < < "aaaaaaa " < <endl;
return   0;
}
发表于:2007-05-16 17:03:0815楼 得分:0
明天试,今天下班了,谢谢你先,能用再好好谢你,呵呵
发表于:2007-05-16 18:15:3216楼 得分:5
和你的dll有关,需要使用   相同的调用约定
发表于:2007-05-17 09:52:5517楼 得分:0
测试程序代码能写详细点么,包含文件也写出来
发表于:2007-05-17 13:59:3318楼 得分:0
//   testdll.h   ----------------------
#ifndef   _testdll_h_
#define   _testdll_h_

#ifdef   testdll_exports
#define   testdll_api   __declspec(dllexport)
#else
#define   testdll_api   __declspec(dllimport)
#endif

#ifdef   __cplusplus
extern   "c "   {
#endif

typedef   xx   int;

testdll_api   xx*   __stdcall   jlda();

#ifdef   __cplusplus
}
#endif

#endif   //   _testdll_h_

//   testdll.cpp   ---------------------
//#define   testdll_exports
#include   "testdll.h "

xx*   jlda()
{
return   null;
}


//   main.cpp   ------------------------
#include   <windows.h>
#include   "testdll.h "

int   main(int   argc,   char*   argv[])
{
xx*   a;
a   =   jlda();
if(a==null)
    printf( "a   is   null.\r\n ");
}
发表于:2007-05-17 14:04:2619楼 得分:0
调试dll:
vc打开dll工程,菜单project--> settings,debug页,EXECutable   for   debug   session选择加载该dll的exe,ok,在dll函数中设断点,执行……
发表于:2007-05-23 11:37:4320楼 得分:0
给分了,不试了,这个问题跳过去了


快速检索

最新资讯
热门点击