Home > Software engineering >  Vfb call Stdcall cdcel, COM components
Vfb call Stdcall cdcel, COM components

Time:09-16

Send a Vfb call Stdcall cdcel, COM components example
Stdcall, cdcel DLL call so easy to say, for example of COM components
1, vb6 create a DLL project, modify the class called EventClass
Write the following class code:
The Public Event OnEvent ()
The Public Event OnOtherEvent ()
Public Sub DoRaiseEvent ()
RaiseEvent OnEvent
MsgBox "test event 1
"End Sub
Public Sub DoOtherRaiseEvent ()
RaiseEvent OnOtherEvent
MsgBox "test event 2
"End Sub
2, create a Vfb engineering to add the following code:
Public area:
Type ExcelSink Extends Object
Declare Virtual Function QueryInterface (ByVal riid As REFIID, ByVal ppvObject As LPVOID Ptr) As HRESULT
Declare Virtual Function AddRef () As ULong
Declare Virtual Function Release () As ULong
Declare Virtual Function GetTypeInfoCount (ByVal pctinfo As UINT Ptr) As HRESULT
Declare Virtual Function GetTypeInfo (ByVal iTInfo As UINT, ByVal lcid As lcid, ByVal ppTInfo As ITypeInfo Ptr Ptr) As HRESULT
Declare Virtual Function GetIDsOfNames (ByVal riid As Const IID Const Ptr, ByVal rgszNames As LPOLESTR Ptr, ByVal cNames As UINT, ByVal lcid As lcid, ByVal rgDispId As DISPID Ptr) As HRESULT
Declare Virtual Function Invoke (ByVal dispIdMember As DISPID, ByVal riid As Const IID Const Ptr, ByVal lcid As lcid, ByVal wFlags As WORD, ByVal pDispParams As DISPPARAMS Ptr, ByVal pVarResult As the VARIANT Ptr, ByVal pExcepInfo As EXCEPINFO Ptr, ByVal puArgErr As UINT Ptr) As HRESULT
Which As ULong
End Type
The Function ExcelSink. QueryInterface (ByVal riid As REFIID, ByVal ppvObject As LPVOID Ptr) As HRESULT
* ppvObject=@ this
The Function=S_OK
End the Function
The Function ExcelSink. AddRef () As ULong
This. Which +=1
The Function=This. Which
End the Function
The Function ExcelSink. Release () As ULong
This. Which -=1
The Function=This. Which
End the Function
The Function ExcelSink. GetTypeInfoCount (ByVal pctinfo As UINT Ptr) As HRESULT
* pctInfo=0
Return E_NOTIMPL
End the Function
The Function ExcelSink. GetTypeInfo (ByVal iTInfo As UINT, ByVal lcid As lcid, ByVal ppTInfo As ITypeInfo Ptr Ptr) As HRESULT
Return E_NOTIMPL
End the Function
The Function ExcelSink. GetIDsOfNames (ByVal riid As Const IID Const Ptr, ByVal rgszNames As LPOLESTR Ptr, ByVal cNames As UINT, ByVal lcid As lcid, ByVal rgDispId As DISPID Ptr) As HRESULT
Return E_NOTIMPL
End the Function
The Function ExcelSink. Invoke (ByVal dispIdMember As DISPID, ByVal riid As Const IID Const Ptr, ByVal lcid As lcid, ByVal wFlags As WORD, ByVal pDispParams As DISPPARAMS Ptr, ByVal pVarResult As the VARIANT Ptr, ByVal pExcepInfo As EXCEPINFO Ptr, ByVal puArgErr As UINT Ptr) As HRESULT
The Select Case dispIdMember
Case 1
MessageBox (0, 1 "my events", "", 0)
Case 2
MessageBox (0, "my event 2", "", 0)
End the Select
The Function=0
End the Function

The Function Advise (ByVal MeObj As IDispatch Ptr, ByVal pEvtObj As IDispatch Ptr, ByVal m_riidEvt As IID Ptr) As HRESULT
If pEvtObj=Null Then Return E_POINTER
Dim pCPC As IConnectionPointContainer Ptr
Dim hr As HRESULT=IUnknown_QueryInterface (MeObj @ IID_IConnectionPointContainer, @ pCPC)
If hr & lt;> S_OK Or pCPC=Null Then
Return the hr
End the If
Dim pCP As IConnectionPoint Ptr
Hr=pCPC - & gt; LPVTBL - & gt; FindConnectionPoint (pCPC m_riidEvt, @ pCP)
If hr & lt;> S_OK Or pCP=Null Then
AfxSafeRelease (pCPC)
Return the hr
End the If
Dim m_dwCookie As dwords
If m_dwCookie Then hr=pCP - & gt; LPVTBL - & gt; Unadvise (pCP, m_dwCookie)
M_dwCookie=0
Hr=pCP - & gt; LPVTBL - & gt; Advise (pCP, Cast (IUnknown Ptr, pEvtObj), @ m_dwCookie)
If hr & lt;> S_OK Then MessageBox (0, "8", "", 0)
AfxSafeRelease (pCPC)
AfxSafeRelease (pCP)
Return the hr
End the Function

Call the area: (button)

Dim pAxHost As CAxHost Ptr
Dim AppPtr As IDispatch Ptr=pAxHost - & gt; CreateObject (" test. EventClass ")
Dim pDisp As CDispInvoke=AppPtr
If pDisp. DispPtr=Null Then MessageBox (0, "there is something wrong with AppPtr", "test", 0)
Dim MySink As ExcelSink
Dim pSink As IDispatch Ptr
MySink. QueryInterface (@ IID_IDispatch, @ pSink)
Const AFX_IID___EventClass="{B73195A6-8732-44 a2 - e6e1d6ae3e8 BC0F - 1}"
Dim EventIID As clsids
CLSIDFromString (AFX_IID___EventClass, @ EventIID)
Advise (pDisp DispPtr, pSink, @ EventIID)
PDisp. Invoke (" DoRaiseEvent ")
PDisp. Invoke (" DoOtherRaiseEvent ")

3, including AFX_IID___EventClass need to check the IID of the interface registry events
'[
'uuid (B73195A6 a2-8732-44 - e6e1d6ae3e8 BC0F - 1),
'version (1.0),
'hidden,
'nonextensible
']
'dispinterface __EventClass {
'the properties:
'the methods:
'[id (0 x00000001)]
'void OnEvent ();
'[id (0 x00000002)]
'void OnOtherEvent ();
'};
The UUID or VFB used to own tool "in the COM type library viewer"
Generate bi file copying the constants or directory compiled in live,

CodePudding user response:

Event UUID with VFB own tools "COM type library viewer" generation of bi, directly in the generated exe directory, compilation can!
  • Related