类成员方法 [英] Class member method

查看:58
本文介绍了类成员方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext,DWORD

dwMessageId,PVOID pMsgBuffer)


我希望该方法是类成员方法,因此它可以访问

类变量,但不知道该怎么做?

我仍​​然收到错误当我尝试使用它时。

提前感谢您的帮助。

问候。


Hi everyone,

HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD
dwMessageId, PVOID pMsgBuffer)

I want that method to be class member method so it could have access to
class variables, but don''t know how to do it ?
I still receive errors when I try to use it.
Thanks in advance for help.
Regards.


推荐答案

" MacFly" <毫安******* @ wp.pl>在消息中写道

news:c1 ********** @ nemesis.news.tpi.pl ...
"MacFly" <ma*******@wp.pl> wrote in message
news:c1**********@nemesis.news.tpi.pl...
大家好,

HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext,DWORD
dwMessageId,PVOID pMsgBuffer)

我希望该方法是类成员方法,因此它可以访问
到类变量,但不知道怎么做?
当我尝试使用它时仍然会收到错误。
Hi everyone,

HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD
dwMessageId, PVOID pMsgBuffer)

I want that method to be class member method so it could have access to class variables, but don''t know how to do it ?
I still receive errors when I try to use it.




这是偏离主题的,因为你正在使用一些

平台特定的宏。一个很好的小组将发布到

microsoft.public.dotnet.languages.vc。


但是,我想你会发现你可以制作功能静止

成员没有错误。


Jonathan



This is off-topic, since the you''re using a number of
platform-specific macros. A good group to post to would be
microsoft.public.dotnet.languages.vc.

However, I think you will find that you can make the function a static
member without error.

Jonathan


相反,这不是关于主题。


基本问题是如何通过c风格的

回调来关联类的实例。

我不确定回调的具体细节,但看起来像

pvUserContext可以用来保存你的类的实例(强制转换为void
指针)。如果是这种情况,那么只需将您的类的实例

传递给最初接受pvUserContext变量的例程,然后在DirectPlayMessageHandler的

上下文中,将pvUserContext转换为类类型的

指针并从那里开始。


这样的东西


Initialize_Function((void *)& your_class_instance,DirectPlayMessageHandler,/ *

etc * /);


// ...


HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext,DWORD

dwMessageId,PVOID pMsgBuffer)

{

your_class_type * pointer_to_your_class_instance =(your_class_type

*)pvUserContext;

pointer_to_your_class_instance-> method1(); //或者你想要的任何方法

电话

//等等

}


得到它?

Jonathan Turkanis写道:
On the contrary, this is not at all off topic.

The basic question is how to associate an instance of a class through c-style
callbacks.

I''m not sure about the specifics of the callback, but it looks like the
pvUserContext could be used to hold the instance of your class (cast as a void
pointer). If that is the case, then simply pass in the instance of your class
to the routine that initially takes the pvUserContext variable, then in the
context of the DirectPlayMessageHandler, simply cast the pvUserContext to a
pointer of your class type and go from there.

Something like this

Initialize_Function((void *)&your_class_instance, DirectPlayMessageHandler, /*
etc */);

// ...

HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD
dwMessageId, PVOID pMsgBuffer)
{
your_class_type * pointer_to_your_class_instance = (your_class_type
*)pvUserContext;
pointer_to_your_class_instance->method1(); // or whatever methods you want to
call
// etc.
}

Get it?
Jonathan Turkanis wrote:

" MacFly" <毫安******* @ wp.pl>在消息中写道
新闻:c1 ********** @ nemesis.news.tpi.pl ...

"MacFly" <ma*******@wp.pl> wrote in message
news:c1**********@nemesis.news.tpi.pl...
大家好,

HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext,DWORD
dwMessageId,PVOID pMsgBuffer)

我希望该方法成为类成员方法,以便它可以访问
Hi everyone,

HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD
dwMessageId, PVOID pMsgBuffer)

I want that method to be class member method so it could have access


类变量,但不知道怎么做?
当我尝试使用它时仍然会收到错误。
class variables, but don''t know how to do it ?
I still receive errors when I try to use it.



这是关闭的-topic,因为你使用了许多特定于平台的宏。一个很好的小组将发布到
microsoft.public.dotnet.languages.vc。

但是,我认为你会发现你可以使这个功能成为一个静态的会员没有错误。

Jonathan



This is off-topic, since the you''re using a number of
platform-specific macros. A good group to post to would be
microsoft.public.dotnet.languages.vc.

However, I think you will find that you can make the function a static
member without error.

Jonathan



" Julie" <菊*** @ aol.com>在留言中写道

新闻:40 *************** @ aol.com ...
"Julie" <ju***@aol.com> wrote in message
news:40***************@aol.com...
相反,这是完全不是主题。

基本问题是如何通过c风格的回调将类
的实例关联起来。


我认为OP的问题在于他或她想通过使其成为会员来给予

回调函数访问权限,但是<由于win32回调函数不能是非静态的
成员,因此获得错误。
得到错误。这就是为什么我说这不是主题。


你的例子涉及代码


HRESULT WINAPI DirectPlayMessageHandler

(PVOID pvUserContext,DWORD dwMessageId,PVOID pMsgBuffer)

{

// ...

pointer_to_your_class_instance-> method1( );

// ..

}


如果method1是私有的,该怎么办?这就是OP试图解决的问题。

得到它?
On the contrary, this is not at all off topic.

The basic question is how to associate an instance of a class through c-style callbacks.
I think the OP''s problem was that he or she wanted to give the
callback function access priviledges by making it a member, but was
getting errors because win32 callback functions can''t be a non-static
members. That''s why I said it''s off topic.

Your example involved the code

HRESULT WINAPI DirectPlayMessageHandler
( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer)
{
// ...
pointer_to_your_class_instance->method1();
// ..
}

What if method1 is private? That''s the problem the OP was trying to
solve.
Get it?




我想所以;你呢?


Jonathan



I think so; do you?

Jonathan


这篇关于类成员方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆