创建对象时应用程序崩溃
我有一个继承自 IDirectInputA 接口的类。
这里: http://pastebin.com/QuHP02ai
所以,当我尝试创建这个对象时,应用程序崩溃了(从某处调用 CorExitProcess)。我做错了什么?
ps 直接输入 v.7
p.ps
此代码创建对象。我删除了其中的一些代码,除了主要部分
IDirectInputA** ppDI;
HRESULT hr = _DirectInputCreateA(hinst, dwVersion, ppDI, punkOuter);
xDirectInputA xDI = new xDirectInputA((IDirectInputA*)(*ppDI));
I have a class which inherits from IDirectInputA interface.
here: http://pastebin.com/QuHP02ai
so, when i try to create object of this, application crashes (calls CorExitProcess from somewhere). What i did wrong?
p.s. Direct input v. 7
p.p.s.
this code creates object. I deleted some code from it, except the main part
IDirectInputA** ppDI;
HRESULT hr = _DirectInputCreateA(hinst, dwVersion, ppDI, punkOuter);
xDirectInputA xDI = new xDirectInputA((IDirectInputA*)(*ppDI));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您创建实例时,您传递了一个指向 IDirectInputA 的指针,对吗?你传递什么指针?如果传递未初始化或空指针,您将得到未定义的行为。
When you create your instance, you pass a pointer to IDirectInputA, right? What pointer do you pass? If you pass an uninitialized or a null pointer, you will get undefined behavior.
说实话,你想做的事情比你想象的要复杂。问题出在你到底想做什么。您是否尝试包装 IDirectInputA 或者尝试完全重新实现它。
如果您尝试包装它,请执行以下操作:
然后按如下方式创建派生类:
现在您传递 xDirectInputA 指针,而不是从 DirectInputCreate 返回的普通指针。您现在可以拦截通过类的每条消息。
如果您尝试自己完全重新实现,那就要复杂得多。您将需要完全实现 COM 对象。您最好将 DInput.DLL 与包含您的实现的可执行文件放在一起。总而言之,如果您真的知道自己在做什么,那么这只是您应该尝试的事情。
如果您想全面学习 COM,我建议您购买 Don Box 的 Essential COM。这是一本非常有帮助的书。
TBH what you are trying to do is more complicated than you think. The problem arises in what exactly you are trying to do. Are you trying to wrap IDirectInputA OR are you trying to completely re-implement it.
If you are trying to wrap it do the following:
Then create your derived class as follows:
Now you pass your xDirectInputA pointer around instead of the normal pointer returned from DirectInputCreate. You can now intercept every message that goes through the class.
If you are trying to do your own full re-implementation it is a LOT more complicated. You are going to need to fully implement the COM object. You'll be best off putting a DInput.DLL alongside the executable that contains your implementation. All in though this is only something you should try if you REALLY know what you are doing.
If you wish to learn COM fully I suggest purchasing Essential COM by Don Box. Its a VERY helpful book.