在Borland C+中处理C#COM对象引发的事件+;应用 我花了很多时间搜索和实验,但是我还没有能够实现C++和Borland C++ Builder 6之间的完全互操作性(特别是在处理C语言对象中提出的C++应用程序中的事件)。 我已经能够从C++应用程序调用COM对象,但是我无法处理事件。
我已经成功地在VC++和COM之间实现了事件处理(通过事件接收器),这要感谢在Borland C+中处理C#COM对象引发的事件+;应用 我花了很多时间搜索和实验,但是我还没有能够实现C++和Borland C++ Builder 6之间的完全互操作性(特别是在处理C语言对象中提出的C++应用程序中的事件)。 我已经能够从C++应用程序调用COM对象,但是我无法处理事件。,c#,c++,com,event-handling,C#,C++,Com,Event Handling,我已经成功地在VC++和COM之间实现了事件处理(通过事件接收器),这要感谢 我在C++ Builder 6中无法重新创建这个。 有人有这样的例子吗 [编辑] 很抱歉问了这么模糊的问题。我将规划我到目前为止所得到的 使用我找到的一个示例,我有以下ManagedMusic名称空间: using System; using System.Runtime.InteropServices; namespace ManagedMusic { public delegate void Stopped_
我在C++ Builder 6中无法重新创建这个。 有人有这样的例子吗
[编辑] 很抱歉问了这么模糊的问题。我将规划我到目前为止所得到的 使用我找到的一个示例,我有以下ManagedMusic
名称空间:
using System;
using System.Runtime.InteropServices;
namespace ManagedMusic
{
public delegate void Stopped_EventHandler(byte songTitle, byte time);
[Guid("285C5024-2E30-4089-AE2D-90A62F2107DE")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMusicEvents
{
void Stopped(byte songTitle, byte time);
}
[Guid("0CDD4767-A776-49ad-97BA-225BAD074E16")]
public interface IMusic
{
byte Play(byte songTitle, byte notify);
byte GetSongTitle();
void SetSongTitle(byte b);
}
[Guid("6F6C45D9-E259-48ad-B35E-DFC218DB559B"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(ManagedMusic.IMusicEvents))]
public class Music : IMusic
{
private byte m_songTitle;
public event Stopped_EventHandler Stopped;
public Music()
{
this.m_songTitle = 0;
}
public byte GetSongTitle()
{
return m_songTitle;
}
public void SetSongTitle(byte b)
{
this.m_songTitle = b;
}
public byte Play(byte songTitle, byte notify)
{
this.m_songTitle = songTitle;
if(notify == 1)
{
Stopped(this.m_songTitle, 200);
}
return 123;
}
}
}
我有正确的设置(在内置项目设置之后注册类型lib,等等)
< P>我创建了一个新的C++包名为“代码> MusicPackage <代码>,并导入了<代码>管理音乐< /COD> Type IL.
< P> C++ Cuilder生成导入管理MultICIKTLB(.h和.cp文件)和管理MuleCixOCX(.h和.cp文件),其中包括事件接收器。< /P>
我在C++ Builder中创建了一个MyCICE客户端项目。它包含一个表单、一个按钮和一个显示歌曲标题的文本框(按按钮设置)
按钮处理程序代码如下所示:void __fastcall TfrmMusic::btnPlayClick(TObject *Sender)
{
myMusic->Play(1, 0);
txtSongTitle->Text = myMusic->GetSongTitle();
ShowMessage("Should see a 1 in the textbox");
ShowMessage("Should get an error now because an event is being raised.");
myMusic->Play(1, 1); //Sets the SongTitle and also raises an event. - Error is here
}
COM事件处理程序代码为:
void __fastcall TfrmMusic::myMusicStopped(TObject *Sender,
unsigned_char songTitle, unsigned_char time)
{
ShowMessage("Receive an event.");
}
错误是“this->Play(歌曲标题,通知,(unsigned_char*)&pRetVal)”:未在@ManagedMusic_TLB.h/164实现
代码是(生成文件ManagedMusic_TLB.h)
unsigned\u char\u快速呼叫播放(unsigned\u char songtle/*[in]*/,unsigned\u char notify/*[in]*/)
{
未签名字符pRetVal;
OLECHECK(这个->播放(歌曲标题,通知,(unsigned_char*)&pRetVal));如果你能详细说明你已经尝试了什么以及失败的地方,也许会有所帮助。
unsigned_char __fastcall Play(unsigned_char songTitle/*[in]*/, unsigned_char notify/*[in]*/)
{
unsigned_char pRetVal;
OLECHECK(this->Play(songTitle, notify, (unsigned_char*)&pRetVal)); <--- Line 164
return pRetVal;
}