Click here to Skip to main content
15,904,653 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hello dears
i want convert this below code from vb to c++/mfc.

VB
Set objNet = CreateObject("WScript.NetWork")
    c = c & "UserName: " & objNet.UserName & vbCrLf
    c = c & "ComputerName: " & objNet.ComputerName & vbCrLf
            c = c & "DomainName: " & objNet.UserDomain & vbCrLf

i use this below code in c++.
but i don't know how to get "UserName" or "ComputerName".

VB
CoInitializeEx(0, COINIT_MULTITHREADED); 
CLSID clsid; 
HRESULT hr = CLSIDFromProgID(L"WScript.NetWork", &clsid);
if(FAILED(hr)) 
{ 
	printf("CLSIDFromProgID() failed");
	return;
} 
IDispatch *pWApp;
hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL,IID_IUnknown, (void **)&pWApp);
if(FAILED(hr)) { 
	printf("CoCreateInstance() failed");
	return; 
}

DISPID dispID;
VARIANT pvResult;
LPOLESTR ptName=L"AddPrinterConnection";
unsigned int FAR* pctinfo;
pctinfo=new unsigned int FAR[1000];

/*
but when i run this two lines of code the program has error.
*/
VB
pWApp->GetTypeInfoCount(pctinfo);

hr = pWApp->GetIDsOfNames(IID_NULL, &ptName, 1, LOCALE_USER_DEFAULT, &dispID);
Posted
Updated 1-Nov-12 12:41pm
v2
Comments
Pablo Aliskevicius 4-Nov-12 2:59am    
Did you try #import?

1 solution

Instead of IID_IUnknown, try IID_IDispatch. This is the one with GetTypeInfoCount and GetIDsOfNames.
Anyway, I'd suggest using the following:
C++
#import "C:\WINDOWS\system32\wshom.ocx" named_guids rename_namespace("ws")

You'll get some smart pointers in namespace "ws".

Hope this helps,
Pablo.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900