荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: oopilix (优雅的), 信区: Visual
标  题: [合集]看看是调用了那个函数????
发信站: 荔园晨风BBS站 (Mon Sep  1 13:13:25 2003), 站内信件

littlebao (爱拼才会赢) 于Sun Aug 24 11:06:00 2003提到:

昨天看com的包容和聚合时一个函数调用的问题搞的我头晕脑胀的
原来一切都是虚函数搞的鬼。大家看看下面的
pB->BFun1() ;
pB->BFun2() ;
pB->BFun3()
分别调用的是那个函数??

#include "stdafx.h"
#include "iostream"
using namespace std ;

class CA
{
public :
        virtual void fun1() = 0 ;
        virtual void fun2() = 0 ;
        virtual void fun3() = 0 ;
};

class CB
{
public :
        virtual void BFun1() = 0 ;
        virtual void BFun2() = 0 ;
        virtual void BFun3() = 0 ;
};

class CC : public CA
{
public :
        virtual void fun1() {cout<<"fun1"<<endl ;}
        virtual void fun2() {cout<<"fun2"<<endl ;}
        virtual void fun3() {cout<<"fun3"<<endl ;}

};

int _tmain(int argc, _TCHAR* argv[])
{
        CB * pB = NULL ;
        CC Ctest ;
        pB = reinterpret_cast<CB *>(static_cast<CA*>(&Ctest)) ;
        pB->BFun1() ;
        pB->BFun2() ;
        pB->BFun3() ;
        return 0;
}


oopilix (优雅的) 于Sun Aug 24 13:33:18 2003提到:

运行了一下,输出是调用了CC的虚函数实现。
用reinterpret_cast可以强制关联两个类并转换pB为CC类的指针。
所以输出是CC的各个函数吧。

昨天看com的包容和聚合时一个函数调用的问题搞的我头晕脑胀的
原来一切都是虚函数搞的鬼。大家看看下面的
pB->BFun1() ;
pB->BFun2() ;
pB->BFun3()
分别调用的是那个函数??

#include "stdafx.h"
#include "iostream"
using namespace std ;

class CA
{
public :
        virtual void fun1() = 0 ;
        virtual void fun2() = 0 ;
        virtual void fun3() = 0 ;
};

class CB
{
public :
        virtual void BFun1() = 0 ;
        virtual void BFun2() = 0 ;
        virtual void BFun3() = 0 ;
};

class CC : public CA
{
public :
        virtual void fun1() {cout<<"fun1"<<endl ;}
        virtual void fun2() {cout<<"fun2"<<endl ;}
        virtual void fun3() {cout<<"fun3"<<endl ;}

};

int _tmain(int argc, _TCHAR* argv[])
{
        CB * pB = NULL ;
        CC Ctest ;
        pB = reinterpret_cast<CB *>(static_cast<CA*>(&Ctest)) ;
        pB->BFun1() ;
        pB->BFun2() ;
        pB->BFun3() ;
        return 0;
}


littlebao (爱拼才会赢) 于Sun Aug 24 14:15:51 2003提到:

其实这是vtbl在其作用,
试着把CB或CA中的函数增加或删除就知道了
reinterpret_cast把CC类型的指针强制转换为CB型的,
pB虽然是CB型的,但其实它是指向CC的vtbl的。
昨天跟踪聚合时的一个类函数时,这一点可把我搞了一个一整天,两个类明明没有
继承关系调用一个类的函数却跑到另一个类里去了。



oopilix (优雅的) 于Sun Aug 24 14:27:19 2003提到:

我式过了,很有趣,呵:)
而且结果和CA的函数的排列有关。
其实这是vtbl在其作用,
试着把CB或CA中的函数增加或删除就知道了
reinterpret_cast把CC类型的指针强制转换为CB型的,
pB虽然是CB型的,但其实它是指向CC的vtbl的。
昨天跟踪聚合时的一个类函数时,这一点可把我搞了一个一整天,两个类明明没有
继承关系调用一个类的函数却跑到另一个类里去了。



littlebao (爱拼才会赢) 于Sun Aug 24 14:31:47 2003提到:

呵呵,现在我也觉得很有趣,可是昨天可把我害惨了。
因为vtbl中函数的顺序跟声明时的是一样的,所以把CA中的函数调换
就会调用不同的函数。



oopilix (优雅的) 于Sun Aug 24 14:58:09 2003提到:

嗯,呵。
呵呵,现在我也觉得很有趣,可是昨天可把我害惨了。
因为vtbl中函数的顺序跟声明时的是一样的,所以把CA中的函数调换
就会调用不同的函数。



tec (JL~酷夏凉风) 于Sun Aug 24 19:57:59 2003提到:

推荐你看《COM本质论》这本书,
深入浅出剖析COM的原理,非常好的一本书。



littlebao (爱拼才会赢) 于Sun Aug 24 20:36:54 2003提到:

有时间是要看一下,你学过com?有时间大家交流一下!!



tec (JL~酷夏凉风) 于Sun Aug 24 20:52:10 2003提到:

学过一点吧,这本书也只是看了前半部分,后面的没时间看完,
不过觉得这本书确实讲解的不错,所以有时间再把它看完。

交流当然没问题,有能力解决的一定帮忙,只是现在要忙于准备
考研,所以平时比较少看编程的书籍了,也比较少上BBS,交流
的机会也许不多。:)



littlebao (爱拼才会赢) 于Sun Aug 24 21:07:30 2003提到:

对了,想问一下在.net里对应6.0的
那个Additional dlls在那里了,怎么我就是找她不着。
调试时很不爽。



tec (JL~酷夏凉风) 于Sun Aug 24 21:31:31 2003提到:

对不起,没用过.net的IDE,我想应该也是在project settings
的debug tab里吧,没有吗?



littlebao (爱拼才会赢) 于Sun Aug 24 21:50:22 2003提到:

.net没有setting的,都是属性操作。
还想问一下,在dll里引出函数的时候加序号和没加序号有什么区别
我在.net里如果加了序号他就会发出警告,但是在6.0里如果我用alt建立com
他的引出的函数是加了序号的,真是奇怪。还有引出函数的名字用双引号和没用双引号
有什么区别。



tec (JL~酷夏凉风) 于Sun Aug 24 23:00:37 2003提到:

加序号与不加序号的区别记得在什么地方看过,不过记不起来了,
所以特地查了下MSDN,下面你自己看看。
警告的信息是什么,贴出来看看。
还有你说导出时什么加引号是什么意思,这个不明白。

Other useful features of the DEF file is use of the ordinal number and
the NONAME flag.
................
The ordinal number can be any decimal number usually set to indicate the
 number of functions in the DLL, which in turn provides a shorthand
method for getting the address of the function in the DLL when
GetProcAddress function is used (discussed in the following section on
explicit linking).

................

Explicit dynamic linking is used when you want to load the DLL only when
 you are ready to call the functions in the DLL in your application.
When you are done using the functions, you can unload the DLL from
memory, thus saving memory space when the application is running, and
load another DLL for some other function calls. The two functions used
to achieve this are LoadLibrary and FreeLibrary. To get the function
addresses GetProcAddress is used. GetProcAddress can use the actual
function name or the ordinal number of the function as associated in the
 DEF file, which we discussed before. The use of the ordinal number lets
 GetProcAddress locate the function in the DLL function table quickly
instead of searching the table with a function name string. If the
NONAME flag is used in the DEF file, GetProcAddress must use the ordinal
 number. To get the function address through the ordinal number, the
MAKEINTRESOURCE macro is used.
................



littlebao (爱拼才会赢) 于Sun Aug 24 23:14:07 2003提到:

warning LNK4222: exported symbol 'DllGetClassObject' should not be assigned
an ordinal
但是书上明明说可以加序号的,而且用alt建com时也是加序号的。
我是说用LIBRARY 说明引出的dll名时,用.net建立的def是不用双引号的
比如LIBRARY     InnerComp
而用6.0通过atl建立com时却加了双引号
比如
LIBRARY      "InnerComp.dll"



littlebao (爱拼才会赢) 于Sun Aug 24 23:24:17 2003提到:

哦,原来加序号是为了GetProcAddress()的快速调用,
但奇怪.net竟然会引起竟然,ft。



oopilix (优雅的) 于Mon Aug 25 09:42:16 2003提到:

解决方案资源管理器的最上面的引用?


littlebao (爱拼才会赢) 于Mon Aug 25 10:01:56 2003提到:

不懂,什么意思???



oopilix (优雅的) 于Mon Aug 25 10:15:15 2003提到:

你想引用或联接入其他dll,可以在解决方案管理器上面那个‘引用‘
右击它你就知道了。



littlebao (爱拼才会赢) 于Mon Aug 25 10:25:15 2003提到:

解决方案管理器?第一次听说,干什么用的?在那里?



oopilix (优雅的) 于Mon Aug 25 10:26:11 2003提到:

?你不是装了.net?打开视图菜单就知道了
解决方案管理器?第一次听说,干什么用的?在那里?



littlebao (爱拼才会赢) 于Mon Aug 25 10:38:05 2003提到:

你是说solution explorer?
中文名是叫这个吗,没听说过,也没看过.net的书。
那个references就相当于6.0的additional dlls?是调试dll用的?



littlebao (爱拼才会赢) 于Mon Aug 25 10:44:13 2003提到:

不行啊,不可以加入自己编的dll,说什么 “error reference”



oopilix (优雅的) 于Mon Aug 25 10:46:59 2003提到:

你装了英文版阿?怪不得。中文名就是解决方案管理器。
references就是我说的引用。用来import dll库的。你是想调试dll?
有专门的工具的阿


oopilix (优雅的) 于Mon Aug 25 10:47:55 2003提到:

你的dll接口问题把,肯定可以插入自己的dll.你在.net做个dll看看
,不要vs6的,不一定完全兼容。
不行啊,不可以加入自己编的dll,说什么 “error reference”



littlebao (爱拼才会赢) 于Mon Aug 25 10:53:35 2003提到:

哦,还有中文版的?没见过,不过觉得英文版的挺好的
6.0的中文版就很垃圾,里面的一些名称都翻译的很糟糕而且经常有莫名其妙的错
只用过几次就没用了,不知道.net的中文版怎么样?



oopilix (优雅的) 于Mon Aug 25 10:56:34 2003提到:

我也觉得英文版感觉爽,但.net的中文版据说比英文版好。vc6的创天中文版真的垃圾。
我下载过几次英文版,都安装不了。以运行就说有毒。ftftftft
哦,还有中文版的?没见过,不过觉得英文版的挺好的
6.0的中文版就很垃圾,里面的一些名称都翻译的很糟糕而且经常有莫名其妙的错
只用过几次就没用了,不知道.net的中文版怎么样?



littlebao (爱拼才会赢) 于Mon Aug 25 10:57:29 2003提到:

我的dll就是用.net作的啊,我是用regsvr32注册的,都可以用啊。
而且我的外组件和内组件的dll用命令注册都可以用,就是在那里加就说什么error的,
但我加他列出来的那些就不会,奇怪!!!



oopilix (优雅的) 于Mon Aug 25 10:58:51 2003提到:

命名空间呢?


littlebao (爱拼才会赢) 于Mon Aug 25 11:00:23 2003提到:

哦,去11.3 load那个VS.NET.2003.Final.ISO,觉得挺好的,现在都不想用6.0了
只是我的机子跑起来有点慢。



oopilix (优雅的) 于Mon Aug 25 11:01:39 2003提到:

??晕倒。我就是下载那个,一运行就说win95xxxxx病毒。
杀毒后,就运行不聊了。狂ft.

哦,去11.3 load那个VS.NET.2003.Final.ISO,觉得挺好的,现在都不想用6.0了
只是我的机子跑起来有点慢。



littlebao (爱拼才会赢) 于Mon Aug 25 11:02:09 2003提到:

什么命名空间?
dll要用“naespace”?



oopilix (优雅的) 于Mon Aug 25 11:21:46 2003提到:

好象是把,我以前在上面用c#。命名空间很常见。


tec (JL~酷夏凉风) 于Mon Aug 25 12:23:35 2003提到:

LIBRARY语句是指明dll的名称,这里加不加引号关系应该不大,在MSDN查到的
Rules for Module-Definition Statements 文章里有下面两条:

Long filenames containing spaces or semicolons (;) must be enclosed in
quotation marks (").

If a string argument matches a reserved word, it must be enclosed in
double quotation marks (").

也许跟这个有点关系吧。

那个link warning的问题在这里可以找到答案:
http://msdn.microsoft.com/library/default.
asp?url=/library/en-us/vccore/html/vcerrlinkertoolswarninglnk4222.asp

顺便还找到了这个,^_^
http://msdn.microsoft.com/library/default.
asp?url=/library/en-us/dv_vstechart/html/vstchdebugginginvisualstudionet
.asp

No More Additional DLLs
~~~~~~~~~~~~~~~~~~~~~~~~
Another new feature improvement is that now you do not need to specify
additional DLLs to set breakpoints in DLLs on processes running on
your local or remote machine. Visual Studio .NET now dynamically binds
the breakpoints to the DLL as soon as it detects that the DLL loads. All
 you need to do is press F9, or set a breakpoint in the code you want to
 debug, and the debugger binds it when the DLL loads.



littlebao (爱拼才会赢) 于Mon Aug 25 12:32:42 2003提到:

so good !!!
thx!!!!!!!!!

LIBRARY语句是指明dll的名称,这里加不加引号关系应该不大,在MSDN查到的
Rules for Module-Definition Statements 文章里有下面两条:

Long filenames containing spaces or semicolons (;) must be enclosed in
quotation marks (").

If a string argument matches a reserved word, it must be enclosed in
double quotation marks (").

也许跟这个有点关系吧。

那个link warning的问题在这里可以找到答案:
http://msdn.microsoft.com/library/default.
asp?url=/library/en-us/vccore/html/vcerrlinkertoolswarninglnk4222.asp

顺便还找到了这个,^_^
http://msdn.microsoft.com/library/default.
asp?url=/library/en-us/dv_vstechart/html/vstchdebugginginvisualstudionet
.asp

No More Additional DLLs
~~~~~~~~~~~~~~~~~~~~~~~~
Another new feature improvement is that now you do not need to specify
additional DLLs to set breakpoints in DLLs on processes running on
your local or remote machine. Visual Studio .NET now dynamically binds
the breakpoints to the DLL as soon as it detects that the DLL loads. All
 you need to do is press F9, or set a breakpoint in the code you want to
 debug, and the debugger binds it when the DLL loads.



littlebao (爱拼才会赢) 于Mon Aug 25 12:36:28 2003提到:

dll 就不是很清楚,可能我现在的是com组件来得
com组件只需在注册表注册然后就可以通过GetClassObject()和CLSID在
注册表查找相应的组件就行了。



oopilix (优雅的) 于Mon Aug 25 13:00:31 2003提到:

这个我还没式过:)
dll 就不是很清楚,可能我现在的是com组件来得
com组件只需在注册表注册然后就可以通过GetClassObject()和CLSID在
注册表查找相应的组件就行了。



tec (JL~酷夏凉风) 于Mon Aug 25 14:46:34 2003提到:

You're welcome~



littlebao (爱拼才会赢) 于Mon Aug 25 15:53:24 2003提到:

怎么第二个连接打不开,说没有此页??第二个是关于什么的?
下面是介绍调试dll的,很好。
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcce
/htm/evc_guide11_59.asp



tec (JL~酷夏凉风) 于Mon Aug 25 19:28:55 2003提到:

Debugging in Visual Studio .NET
URL太长,直接点击连不上,把它接起来就行了。

你的那个好像直接点也连不上。。



tec (JL~酷夏凉风) 于Mon Aug 25 19:54:12 2003提到:

   这个好像是eMbedded Visual C++ 3.0的,应该不是.net的


littlebao (爱拼才会赢) 于Mon Aug 25 21:02:52 2003提到:

一样,.net可以,6.0也ok,他介绍的那两种方法我都试过了。



tec (JL~酷夏凉风) 于Mon Aug 25 21:14:58 2003提到:

^_^,解决问题就好~



littlebao (爱拼才会赢) 于Mon Aug 25 21:39:53 2003提到:

刚才看了那篇文章,看到一个很有用的功能,试了一下,果然不错,而且我还发现
.net里有一个很好的地方就是调试时可以把那个箭头(就是在断点的那个)
拉到那就那,就是说你把他往回拉都可以,在6.0里调试时就不知道如何向后走,在
.net可以这么方便。
Stepping Into Specific Functions
Another cool, albeit hidden, feature of the debugger is the ability to
 step into a specific function. When you are at a line with multiple nested
functions, or a function call, that will cause you to step into a constructor,
 right-click on the line, and
select Step Into Specific from the shortcut menu. This will enable you to
 select which specific function you want to step into. You can thus avoid
stepping into constructor code you don't care about, and instead go directly
to the function you want to
debug.



tec (JL~酷夏凉风) 于Mon Aug 25 22:25:53 2003提到:

那篇文章我没看完呢。
现在暂时不会学.net,在学Java,平时复习之余只会看一些Java的书,呵呵


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店