DLL with ATL Support
DLL with ATL Support
I have created a windows dll project .
Then I need to use CComPtr, CoCreateInstance, etc in this project.
I don't know what to do exactly.
So I add the following 3 header files to the project:
#include <atlbase.h>
#include <atlcom.h>
#include <atlctl.h>
The project builds OK.
But CoCreateInstance always fall.
I know that there is a kind of project called ATL DLL, is that what I
need?
What is the most convenient thing to do to fix things?
Any help appreciated.
The following is the code scrippt where the function always return
NULL.
//////////////////////////
CComPtr<IHTMLDocument2> GetPageDocumentPtr(CString & htmlString){
HRESULT hr;
CComPtr<IHTMLDocument2> pDoc;
hr = CoCreateInstance(CLSID_HTMLDocument, NULL,
CLSCTX_INPROC_SERVER, __uuidof(IHTMLDocument2), (void **)&pDoc );
if(hr != S_OK){ return pDoc; }
//load document
SAFEARRAY * psa = SafeArrayCreateVector(VT_VARIANT, 0, 1);
VARIANT * param;
bstr_t bsData = (LPCTSTR)htmlString;
hr = SafeArrayAccessData(psa, (LPVOID*)¶m);
param->vt = VT_BSTR;
param->bstrVal = (BSTR)bsData;
hr = pDoc->write(psa); //write your buffer
hr = pDoc->close(); //and closes the document, "applying" your code
SafeArrayDestroy(psa);//Don't forget to free the SAFEARRAY!
//
return pDoc;
}
///////////////////////