자답
https://stackoverflow.com/questions/13456628/use-com-in-c-builder
에 자료가 있습니다.
?Component > Import component... > Import a Type Library > select the library
?Unit Dir Name = and uncheck "Generate Component Wrappers"
?"Add unit to MyProject.cbproj project" > Finish
?in the client class > File > Use Unit... > select the unit that was created
?
in the client class write this code for using the COM DLL:
CoInitialize(NULL); //Init COM library DLLs
ICompany *company;
HRESULT hr = CoCreateInstance ( CLSID_Company,
NULL,
CLSCTX_INPROC_SERVER,
IID_ICompany,
(void**) &company );
if (SUCCEEDED (hr)) {
//TODO here you can use your company object!
//and finally release such resource
company->Release();
}
CoUninitialize();
코드는 얼추 비슷하게 까지 갔는데,
결정적으로 빼먹은것은 File > Use Unit.으로 하지않고, 생성된 파일만 Add 한것 같습니다.(아마도 ㅠㅠ)
JJJ 님이 쓰신 글 :
: 안녕하세요
:
: 저는, C# (.NET) 기반의 DLL을 C++Builder, VisualC++6.0, Delphi에 각각 붙이는 작업을 하고 있습니다.
:
: 그중 C++Builder는 언어자체도 좀 생소하고, 잘 몰라서 여기 전문가 분들께 여쭤보려고 합니다.
:
: 일단 제공된 것은 Dll 파일, Tlb 파일 이렇게 두개를 제공받았습니다. (LinkSMS_DLL.dll, LinkSMS_DLL.tlb)
: 일단 상단 메뉴에 [Component]-[Import Component]로 해당 TLB파일으로 Unit을 새로 만들었고,
: 그러니,
: LinkSMS_DLL_OCX.cpp/h/dcr
: LinkSMS_DLL_TLB.cpp/h
: mscorlib_OCW.cpp/dcr/h
: mscorlib_TLB.cpp/h
: 가 생겨났고, 그것들을 프로젝트 파일에 Add하였습니다.
:
: 추가로 TLB파일도 프로젝트에 Add 하니 정보가 나오더군요. TLB파일을 열어보면,
: LinkSMS_DLL
: └ clsSMS
: └ InterfaceSMS
: └ sendSMS
: 으로 트리가 되어있고,
:
: 제가 쓰려는 함수인, sendSMS를 클릭하여 Parameters를 보면,
: Name Type Modifier
: sIPAddress BSTR [in]
: sPortNo BSTR [in]
: sProjectID BSTR [in]
: sModuleID BSTR [in]
: sMessage BSTR [in]
: sRetVal long* [out, retval]
: 이렇게 되어있습니다.
:
: 코드는
: //---------------------------------------------------------------------------
: #include <vcl.h>
: #pragma hdrstop
:
: #include "Unit1.h"
: #include "LinkSMS_DLL_TLB.h"
: #include "LinkSMS_DLL_OCX.h"
: #include "mscorlib_OCX.h"
: #include "mscorlib_TLB.h"
:
: //---------------------------------------------------------------------------
: #pragma package(smart_init)
: #pragma resource "*.dfm"
: TForm1 *Form1;
: //---------------------------------------------------------------------------
: __fastcall TForm1::TForm1(TComponent* Owner)
: : TForm(Owner)
: {
: }
: //---------------------------------------------------------------------------
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
: InterfaceSMS* ifs;
: TclsSMS* faf;
:
: long aaa;
: long b;
:
: ifs->sendSMS("192.168.10.32", "5000", "A001", "TM01", "CFC00FFC00FFC00A", aaa&);
:
: }
: //---------------------------------------------------------------------------
:
: 이렇게만 써봤는데, sendSMS 함수라인에, Expression syntax 에러가 나고있습니다.
:
: 뭔가 방법이 잘못된걸까요? 이 포럼과 다른 해외사이트도 찾아봤는데 도통 답이 안나오네요..;;
: