How to import a given COM interface in VS.NET?

M

Marcus Heege

Have you tried to use TIBIMP.EXE?
Have you tries addin COM Refeenecs?

I yes and it didn't help, you will have to write the interface yourself
with attributes like

using namespace System;
using namespace System:::Runtime::InteropServices;
[System::Guid("......")]
[InterfaceType(ComInterfaceType::InterfaceIsIUnknown)]
public interface ... {
};

Marcus Heege
 
M

Marcus Heege

And by the way, if you are using C++/CLI it is much better to just include
the header and call the interface via IJW. IJW is much better here, because
you don't have to care about the Com Callable Wrapper's additional reference
count and it is faster.

Marcus Heege
 
L

Lloyd Dupont

And by the way, if you are using C++/CLI it is much better to just include
the header and call the interface via IJW. IJW is much better here,
because you don't have to care about the Com Callable Wrapper's additional
reference count and it is faster.

uh?... what IJW?
Anyway it's what I probably did as I just include the header and call the
"method".
but I am not sure what I should do about CoInitialize() (and particularly
CoUnitialize)
and I though of C# as I have no idea how to use "the COM beast", whereas I
know how
to use a C# class.

Anyway now it's better... it compile but doesn't link.
I should include some (yet unknown) library to include the symbol:
CoCreateInstance()
 
L

Lloyd Dupont

BTW, what do you think?
I linked with OLE32.LIB and it compiles and linked successfully.

and here is my (short COM) code (so far), does it seems allright to you?
====================================
FontFallback::FontFallback()
{
IMLangFontLink2* pfl;
HRESULT result = CoCreateInstance(
CLSID_CMultiLanguage,
NULL, CLSCTX_ALL,
IID_IMLangFontLink2,
(void**)&pfl);
if(!SUCCEEDED(result))
throw Script::ErrorResult(result);
langfont = pfl;
}
FontFallback::~FontFallback()
{
if( langfont )
langfont->Release();
langfont = NULL;
}
GdiFont^ FontFallback::GetFont(GdiGraphics^ g, wchar_t c)
{
if( !langfont )
throw gcnew ObjectDisposedException("langfont");
if( !g )
throw gcnew ArgumentNullException("g");

DWORD codePages;
HRESULT result = langfont->GetCharCodePages(c, &codePages);
if(!SUCCEEDED(result))
throw Script::ErrorResult(result);

HFONT dest;
result = langfont->MapFont(g->HDC, codePages, c, &dest);
if(!SUCCEEDED(result))
throw Script::ErrorResult(result);
try
{
LOGFONT logfont;
::GetObject(dest, sizeof(LOGFONT), &logfont);
return gcnew GdiFont(&logfont);
}
finally { langfont->ReleaseFont(dest); }
}
 
M

Marcus Heege

Looks good at the first view.

Marcus Heege



BTW, what do you think?
I linked with OLE32.LIB and it compiles and linked successfully.

and here is my (short COM) code (so far), does it seems allright to you?
====================================
FontFallback::FontFallback()
{
IMLangFontLink2* pfl;
HRESULT result = CoCreateInstance(
CLSID_CMultiLanguage,
NULL, CLSCTX_ALL,
IID_IMLangFontLink2,
(void**)&pfl);
if(!SUCCEEDED(result))
throw Script::ErrorResult(result);
langfont = pfl;
}
FontFallback::~FontFallback()
{
if( langfont )
langfont->Release();
langfont = NULL;
}
GdiFont^ FontFallback::GetFont(GdiGraphics^ g, wchar_t c)
{
if( !langfont )
throw gcnew ObjectDisposedException("langfont");
if( !g )
throw gcnew ArgumentNullException("g");

DWORD codePages;
HRESULT result = langfont->GetCharCodePages(c, &codePages);
if(!SUCCEEDED(result))
throw Script::ErrorResult(result);

HFONT dest;
result = langfont->MapFont(g->HDC, codePages, c, &dest);
if(!SUCCEEDED(result))
throw Script::ErrorResult(result);
try
{
LOGFONT logfont;
::GetObject(dest, sizeof(LOGFONT), &logfont);
return gcnew GdiFont(&logfont);
}
finally { langfont->ReleaseFont(dest); }
}
 

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