|
Sorry for the previous reply - I have noticed that the browser stripped my tags too. The definition of loadXML method in the DOMDocument intereface is " HRESULT loadXML ( BSTR xml, VARIANT* vSucceeded)". You use smart pointers and the _com_ptr_t will wrap your method call and will return vSucceeded instead of the HRESULT.VARIANT_TRUE value is -1 and VARIANT_FALSE is 0, so the buffer is loaded by the parser just fine ( you can check by testing doc->xml property : "MessageBoxW( NULL, doc->xml, L"XML", MB_OK);
|
|
|
|
|
MSXML2::IXMLDOMDocumentPtr doc;
hr = doc.CreateInstance("Msxml2.DOMDocument.4.0");
if(FAILED(hr)) return hr;
VARIANT_BOOL vb = doc->loadXML("<customer><first_name>Joe</first_name> <last_name>Smith</last_name></customer>");
if(vb == VARIANT_FALSE) return E_FAIL;
::MessageBox(NULL, doc->xml, NULL, 0);
|
|
|
|
|
Arrgh! Of course! In the back of my head I knew that it returned a VARIANT_BOOL, but I guess I'd just been banging my head against a wall for so long that I couldn't see the problem any more.
Thanks for the help.
|
|
|
|
|
Hi,
I have done an activeX control. I have several problems:
1. At design time in Visual C++ 6, I paste the control in a dialog box and it is filled blank although it should be custom painted. If I launch the dialog under Visual it is properly painted (minus the next problem).
2. At design-time, if changing a custom property value, it is not shown at run-time.
When trying my control in the microsoft test container, all is fine, I have not these problems. I'm a beginner with activex, it maybe explains that.
An idea ?
Nicolas
|
|
|
|
|
If I have the following code on VB:
Dim myObj as Object
Set myObj = CreateObject("MyDCOMServer.MyClass", "ServerName")
How do I do it on Visual C++?
Thanks a lot,
Julian
|
|
|
|
|
Use this.
HRESULT CoCreateInstanceEx(
REFCLSID rclsid, //CLSID of the object to be created
IUnknown *punkOuter, //the controlling IUnknown
DWORD dwClsCtx, //CLSCTX values
COSERVERINFO *pServerInfo,//Machine on which the object is to be instantiated
ULONG cmq, //Number of MULTI_QI structures in pResults
MULTI_QI *pResults //Array of MULTI_QI structures
);
Cheers,
Anand
|
|
|
|
|
Hi !
I'm still beginning with COM ! I'd like to do a very simple ATL component with Visual C++.
The interface of this component would implement only one method, which would return a boolean value.
This value would be read from a Visual Basic app.
The problem is when I use the 'boolean' type for my interface, VB doesn't recognize it. I tried to use the 'short' type, but VB recognize it as an Integer.
What type should I use in my ATL interface so that VB receives a 'Boolean' type ?
Thank you for your help,
Jerome
|
|
|
|
|
Pass a VARIANT structure with VT_BOOL type. For example :
HRESULT Object::Test( /*[out,retval]*/VARIANT* pOut)
{
*pOut = NULL;
CComVariant vRet( true);
vRet.Detach( pOut);
return S_OK;
}
|
|
|
|
|
Just more Info for you.
In C++, TRUE is +1, but VB and automation clients use TRUE as -1 and FALSE as +1.
If you use BOOL, all you can see is clouds of confusion over your application.
so use VARIANT_BOOL(boolean type), VARIANT_TRUE(true),VARINAT_FALSE(false)
Whenever you are using C++(COM), you should avoid using bool, BOOL in your application.
Cheers,
Anand
|
|
|
|
|
I have problem implementing my onIdle function. I have TRACE messages in my onIdle function to see if it is called for but I can't see these TRACE messages and I don't know what I have done wrong.
I have one CWinApp class and one CDialog class and I wan't my onIdle to update my user_interface e.g. dialog_window. I've tried to implement a onIdle function in both the CWinApp class and the CDialog class but I can't see any of my TRACE messages.
Do I have to edit anything in the ON_MESSAGE list or anything like that???
Please, help me..
|
|
|
|
|
Hi,
The foll. is an extract from Paul DiLascia's C++ Q&A column in MSJ-July'97
Unfortunately, this wonderful UI update mechanism doesn't work for dialogs—at least not automatically. You have to hook the pieces up yourself. Fortunately, it's easy. All you have to do is handle WM_KICKIDLE, a private MFC message that MFC sends whenever the dialog is idle (analogous to the app's OnIdle handler) to call UpdateDialogControls yourself.
Look into the article.
Hope this Helps
|
|
|
|
|
Hi !
I'm beginning with COM, and I'd like to do a very simple ATL component with Visual C++.
The interface of this component would implement only one method, which would return a string.
Then, I want to use this component from Visual Basic, and read the string.
The problem I'm having is I don't know how to pass to VB a BSTR. what would be the definition of my Method of the interface ? Can I do this :
HRESULT GetString([out, retval] BSTR str);
In C++, how can I create this BSTR ? Do I have to build the BSTR structure myself from a normal C++ array of chars ?
Thank you for your help,
Jerome
|
|
|
|
|
Jerome C wrote:
what would be the definition of my Method of the interface ?
When you implement method no difference betwenn VB and VC.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Jerome, the GetString should be defined like this :
HRESULT GetString([out, retval] BSTR* str);
In the cpp file:
STDMETHODIMP GetString(BSTR* str)
{
//you must allocate space, vb will call SysFreeString Automatically
*str = SysAllocString("xpto");
return S_OK;
}
If it was a [in] method the str didn't need a pointer.
Cheers,
Joao Vaz
|
|
|
|
|
Thank you both for your help ! It works !!!!
Jerome
|
|
|
|
|
I extracted the system32\vbscript.dll to get the type library(named RegExp.tlb). Then I add the new classes from this tlb to my project! Then I want to new one class of them named IRegExp(derived from COleDispatchDriver), but i don't know whether i need to attach the LPDISPATCH to this instance and how can i do! When i didn't attached it, that is called its default constructor, and run it, I can't not execute it normally! This program is too emengent, so i need ur warmhearted help in time!
[ccode]
void CInetSessionDlg::ParsePage(CString szPattern, CString szContent)
{
//m_regExp's declaration is on other place link this: IRegExp m_regExp;
//The class IMatchCollection and IMatch are both got from the tlb
IMatchCollection * temp;
m_regExp.SetIgnoreCase(TRUE);
m_regExp.SetPattern(szPattern);
if(m_regExp.Test(szContent))
{
temp=new IMatchCollection(m_regExp.Execute(szContent));
for(long i = 0; i < 3/*matches.GetCount()*/; i++)
{
//IMatch match = matches.GetItem(i);
IMatch match = temp->GetItem(i);
CString strLink = match.GetValue();
m_cbHref.AddString(strLink);
}
}
}
[/ccode]
Thanks u very much!
Sincerely, Davidlou
davidlou68@hotmail.com
|
|
|
|
|
Can someone please help me out!!!
I just don't know how to pass/receive binary data between a VB6 client application and an ATL COM Server (EXE).
How can I transform this into COM?
HRESULT MyFunc( unsigned short* pbIn, long cbIn, unsigned short** ppbOut );
Where pbIn is of cbIn-size. The output shall be a size-dynamic buffer holding the result.
Can I use VB6 to call this method using Byte arrays?
Need help
|
|
|
|
|
COM must know at runtime the size of the buffer you want to marshall. So in your case you should declare the method in your IDL file like this :
interface XXX
{
HRESULT MyFunc( [in]long cbIn,[in,size_is(cbIn)] unsigned short *pbIn,[out]long* pbOut,[out,size_is( ,*pbOut)]unsigned short** ppbOut);
};
Or if you want to use the automation marshaller you can pass the array as SAFEARRAY, which is a VARIANT compatible type.
|
|
|
|
|
Hi Stefan, one way that to pass binary data is to use BSTRs, using the api
SysAllocStringByteLen , this creates a string with binary data .
I actually used that doing a atl com object that passed binary data to vb6.
I don't remember well, but since VB6 work with unicode internally , i think that you must allocate 2*nBytes that you want to pass to VB, but I'm not sure if you really need to double the nª of bytes, so you should try the first one.
It's not necessary with BSTR to pass the size, since their size is prefixed at the head of the data, and vb makes use of this.
Hope this helps,
Joao Vaz
|
|
|
|
|
See sample app of COM Variant and Safearrays at
http://www.sellsbrothers.com/tools/CComSafeArray.zip
It also uses VB Clients and C++ COM Object
Best SafeArray Sample that I have seen
(from chris sells site)
|
|
|
|
|
IADsNameTranslate *pNto;
hr = CoCreateInstance
(CLSID_NameTranslate,NULL,CLSCTX_INPROC_SERVER,
IID_IADsNameTranslate,(LPVOID *)&pNto);
if(FAILED(hr))
{
.....
}
CoCreateInstance always fail , HRESULT : 800401f0
any ideas ??
thanx
|
|
|
|
|
You can use Error Lookup Utility ( Comes with Visual Studio) to decode HRESULT. Or add hr,hr in watch window to get full meaning of the hr HRESULT.
HRESULT : 800401f0
means
CoInitialize has not been called.
Deepak Khajuria
|
|
|
|
|
Thanx
|
|
|
|
|
Hi there,
I am trying to switch context within a server. The server is called from an ASP page.
The following code retrieves correctly the client token
but the CreateProcessAsUser fail with error 1314 :
"A required privilege is not held by the client"
the parent account has administrator rights on the local machine. Does he need special privileges like SE_ASSIGNPRIMARYTOKEN_NAME &
SE_INCREASE_QUOTA_NAME ?
the doc say that CreateProcessAsUser enable these privileges automatically. I also uses DCOMCNFG to set impersonation level "delegate", is there a programmatic
way to do this ?
I need help !!
HANDLE hToken,hDup;
CoImpersonateClient();
if ( !OpenThreadToken(
GetCurrentThread(),
TOKEN_ALL_ACCESS ,
FALSE,
&hToken )) {
// openthread error
...
}
CoRevertToSelf();
if ( !DuplicateTokenEx(
hToken,
TOKEN_IMPERSONATE | TOKEN_QUERY |
TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE,
NULL,
SecurityImpersonation,
TokenPrimary,
&hDup
) ) {
// duplicatetoken error
...
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
GetStartupInfo(&si);
if( !CreateProcessAsUser( hDup,
"somecommand",NULL,
NULL,
NULL,
TRUE, NORMAL_PRIORITY_CLASS ,
NULL,
NULL,
&si,
&pi )
)
{
// error
}
|
|
|
|
|
As far as I know the IIS use the IWAM_[machinename] to launch out of process applications, and an anonymous access to IIS will run under IUSR_[machinename] account ( check the users lists from your machine). So if you impersonate your client from your component you will impersonate IWAM_XXX or IUSR_XXX, not the logged on user.
|
|
|
|
|