How Do I Use DispCallFunc with IMLangCodePages::GetCharCodePages

Z

Zoo

Hi.
I want to use the following IMLangCodePages::GetCharCodePages through
DispCallFunc.
----------------------------------------------------
Gets the set of code pages that the given Unicode character belongs to.
Syntax
HRESULT GetCharCodePages( WCHAR chSrc,
DWORD *pdwCodePages
);

from (http://msdn2.microsoft.com/en-us/library/aa741065.aspx)
----------------------------------------------------

So , I'v written code as follows , but it does not work.
(The value of lCodePage is always 0.
I expected the codepage is returned here.
And I thoght I should pass the pointer of lCodePage through lpCodePage.
Since DispFuncCall needs pointer to the parameters ,
I passed varptr(lpCopePage) that is a pointer to a pointer.
What's wrong?)

'''''''''''''''''''''''''' Code
'''''''''''''''''''''''''''''''''''''''''''''''

Option Explicit

Public Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type

Private Const CLSCTX_INPROC = &H1& Or &H2&
Private Const CC_STDCALL = 4

Private Declare Function CoCreateInstance Lib "OLE32" _
(ByRef rclsid As UUID, _
ByVal pUnkOuter As Long, _
ByVal dwClsContext As Long, _
ByRef riid As UUID, _
ByRef ppv As Long) As Long

Private Declare Function DispCallFunc Lib "OLEAUT32" _
(ByVal pvInstance As Long, _
ByVal oVft As Long, _
ByVal CallConv As Long, _
ByVal vtReturn As VbVarType, _
ByVal cActuals As Long, _
ByRef prgvt As Integer, _
ByRef prgpvarg As Long, _
ByRef pvargResult As Variant) As Long

'Vtbl
Public Enum eVtblFunctionOffsetCUrlHistory
' IID_IMLangFontLink2 Interface
vtblOffsetGetCharCodePages = 12 '2 Args
' IUnknwon Interface
vtblOffsetQueryInterface = 0 '2 Args
vtblOffsetAddRef = 4 '0 Arg
vtblOffsetRelease = 8 '0 Arg
End Enum

Private Function CLSID_CMultiLanguage() As UUID
'HKCR\CLSID\{275c23e2-3747-11d0-9fea-00aa003f8646}
With CLSID_CMultiLanguage
.Data1 = &H275C23E2
.Data2 = &H3747
.Data3 = &H11D0
.Data4(0) = &H9F
.Data4(1) = &HEA
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H3F
.Data4(6) = &H86
.Data4(7) = &H46
End With
End Function


Private Function IID_IMLangFontLink2() As UUID
'Interface[IID_IMLangFontLink2]
'HKCR\Interface\{DCCFC162-2B38-11d2-B7EC-00C04F8F5D9A}
With IID_IMLangFontLink2
.Data1 = &HDCCFC162
.Data2 = &H2B38
.Data3 = &H11D2
.Data4(0) = &HB7
.Data4(1) = &HEC
.Data4(2) = &H0
.Data4(3) = &HC0
.Data4(4) = &H4F
.Data4(5) = &H8F
.Data4(6) = &H5D
.Data4(7) = &H9A
End With
End Function

Public Sub GetCharCodePages()
Dim hr As Long
Dim udtCMultiLanguage As UUID
Dim udtIMLangFontLink2 As UUID
Dim lngPMLangFontLink2 As Long
Dim lngPArgs() As Long
Dim intVtArgs() As Integer
Dim varResult As Variant

udtCMultiLanguage = CLSID_CMultiLanguage
udtIMLangFontLink2 = IID_IMLangFontLink2
hr = CoCreateInstance _
(udtCMultiLanguage, _
0&, _
CLSCTX_INPROC, _
udtIMLangFontLink2, _
lngPMLangFontLink2)
If hr <> 0& Then
Debug.Print Err.LastDllError
Err.Raise hr
Else
ReDim intVtArgs(1)
ReDim lngPArgs(1)

Dim bBytes() As Byte
Dim s As String
s = ChrW(&H97)
bBytes = s

Dim lCodePage As Long
Dim lpCodePage As Long
lpCodePage = VarPtr(lCodePage)

intVtArgs(0) = vbLong '''''Instead of WCHAR
lngPArgs(0) = VarPtr(bBytes(0))


intVtArgs(1) = vbLong
lngPArgs(1) = VarPtr(lpCodePage)


Debug.Print lCodePage, lpCodePage

hr = DispCallFunc _
(lngPMLangFontLink2, _
vtblOffsetGetCharCodePages, _
CC_STDCALL, _
vbLong, _
2, _
intVtArgs(0), _
lngPArgs(0), _
varResult)

Debug.Print lCodePage, lpCodePage
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top