|
edit you post and use the <pre></pre> tags around your code.
thanks you
|
|
|
|
|
As you prefer
**************************************************************************
#define POLARITY
#define _WIN32_DCOM
#include
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
int WMIEnableStatic()
{
IWbemLocator *pLocator = NULL;
IWbemServices *pNamespace = 0;
IWbemClassObject * pClass = NULL;
IWbemClassObject * pOutInst = NULL;
IWbemClassObject * pInClass = NULL;
IWbemClassObject * pInInst = NULL;
BSTR path = SysAllocString(L"root\\cimv2");
BSTR ClassPath = SysAllocString(L"Win32_NetWorkAdapterConfiguration");
BSTR InstancePath =
SysAllocString(L"Win32_NetWorkAdapterConfiguration.Index='1'");
BSTR MethodName = SysAllocString(L"EnableStatic");
BSTR ArgName1 = SysAllocString(L"IPAddress");
BSTR ArgName2 = SysAllocString(L"SubNetMask");
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, 0
);
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLocator);
hr = pLocator->ConnectServer(path, NULL, NULL, NULL, 0, NULL, NULL,
&pNamespace);
if(hr != WBEM_S_NO_ERROR)
return 1;
cout << "Connected to WMI" << endl;
hr = CoSetProxyBlanket(pNamespace,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE
);
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
if(hr != WBEM_S_NO_ERROR)
return 1;
hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL);
if(hr != WBEM_S_NO_ERROR)
return 1;
hr = pInClass->SpawnInstance(0, &pInInst);
if(hr != WBEM_S_NO_ERROR)
return 1;
BSTR ip;
ip = SysAllocString(L"10.0.0.3");
BSTR mask;
mask = SysAllocString(L"255.255.255.0");
long index[]={0};
SAFEARRAY *ip_list;
ip_list = SafeArrayCreateVector(VT_BSTR,0,1);
SafeArrayPutElement(ip_list,index,ip);
SAFEARRAY *mask_list;
mask_list = SafeArrayCreateVector(VT_BSTR,0,1);
SafeArrayPutElement(mask_list,index,mask);
VARIANT arg1;
arg1.vt = VT_ARRAY|VT_BSTR;
arg1.parray = ip_list;
hr = pInInst->Put(ArgName1, 0, &arg1, 0);
VARIANT arg2;
arg2.vt = VT_ARRAY|VT_BSTR;;
arg2.parray = mask_list;
hr = pInInst->Put(ArgName2, 0, &arg2, 0);
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL, pInInst,
&pOutInst, NULL);
if(hr != WBEM_S_NO_ERROR){
cout << "ExecMethod failed " << hr;
return 1;
}
VARIANT ret_value;
BSTR strReturnValue = SysAllocString(L"ReturnValue");
hr = pOutInst->Get(strReturnValue, 0, &ret_value, 0, 0);
long ret = V_I4(&ret_value);
if(ret != 0) {
cout << "EnableStatic failed with return code = " << ret;
}else{
cout << "EnableStatic succeeded" << endl;
}
SysFreeString(strReturnValue);
VariantClear(&ret_value);
SysFreeString(ip);
SysFreeString(mask);
SafeArrayDestroy(ip_list);
SafeArrayDestroy(mask_list);
VariantClear(&arg1);
VariantClear(&arg2);
SysFreeString(path);
SysFreeString(ClassPath);
SysFreeString(InstancePath);
SysFreeString(MethodName);
SysFreeString(ArgName1);
SysFreeString(ArgName2);
pClass->Release();
pInInst->Release();
pInClass->Release();
pOutInst->Release();
pLocator->Release();
pNamespace->Release();
CoUninitialize();
return 0;
}
I've never used these before. What's the deal? the code seemed to apear as it should
tom
|
|
|
|
|
Why did you suggest I did that?
It looks terrible, all the formatting has gone!
Tom
|
|
|
|
|
first of all, i told you to EDIT the existing post, to resposting again and again a huge bloc of code.
moreover, why i told you to use it? because Chris asks us to[^] (see 5.)! the code samples should be embraced by pre tags.
at last, it DOES PRESERVE the formating, but you used it wrongly.
if you want to see the empty lines, place at least a space on those lines.
and if you want to see some indentation, just put some spaces at the beginning ot your lines, and you'll see the spaces that doesn't appear in normal case...
oh, i was forgetting : when you put some #include statement, use the < and > html codes to print < > , otherwise, your include headers will be understood as html tags too.
|
|
|
|
|
Thanks to your advice I also noted Chris said:
"Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job."
But, before this gets more out of shape. I agree what you said was completly valid as far as the response protocols I employed is concerned (That won't happen again) but the way you said it did not inspire me to seek to thoroughly correct myself.
Sorry if I pressed your buttons though.
Tom
|
|
|
|
|
i don't think i shouted though. i simply insisted on some words.
you could have said so if my sentence was all in caps...
btw, sorry if i hurted you, but loading the boards with huge posts and reposts is not helping...
|
|
|
|
|
heh! Good post though!
I'm sure glad there's .NET for WMI - doing it in straight C/C++ is wordy!
|
|
|
|
|
Thanks Mark
|
|
|
|
|
Thanks friends TClarke,toxcct and Mila025 for your guide .
|
|
|
|
|
The following won't compile with the following error :
error C2660: 'B::f()' : function does not take 2 arguments
class A{<br />
public:<br />
virtual void f(int a, int b); <br />
};<br />
<br />
class B : public A{<br />
virtual void f(int a)<br />
{<br />
f(a, 1);<br />
}<br />
};
I fail to see the logic error !!! can anyway shed some light ?
Odesh
|
|
|
|
|
-- forget, nothing interresting here --
|
|
|
|
|
toxcct wrote: the function A::f() inherited mush be implemented
Again, this is false. This statement is true only if the function is pure virtual. You can perfectly have a virtual function in the base class which is not implemented in one or several derived classes (even not implemented at all in the derived classes).
|
|
|
|
|
odesh wrote: error C2660: 'B::f()' : function does not take 2 arguments
I think you should try this:
class B : public A
{
virtual void f(int a)
{
A::f(a, 1);
}
};
I hope this helps.
|
|
|
|
|
won't compile more. A::f() is virtual, so, not implemented...
moreover, the compilation error is no B::f() implementation overloads A::f()
|
|
|
|
|
toxcct wrote: A::f() is virtual, so, not implemented...
You can perfectly have a virtual function that is implemented in the base class. Making it virtual doesn't mean that you cannot implement it. I think you mix it with a pure virtual function which is:
virtual void f() = 0;
|
|
|
|
|
Cedric Moonen wrote: You can perfectly have a virtual function that is implemented in the base class
yes, i know that, but it didn't seem to be here...
|
|
|
|
|
The proposed solution solves the compilation error message mentioned in the original post: "error C2660: 'B::f()' : function does not take 2 arguments". In my opinion, just adding an implementation for A::f() is not a solution for original problem. Missing implementation (if really was not done by the author) will be reported on linking phase.
|
|
|
|
|
The problem is that function overloading is limited at the class scope, that means you cannot overload a function in a derived class (or you need to implement the function which is overloaded too).
|
|
|
|
|
Thanks for the help Cedric,
of course the problem i was refering to had nothing to do with implementation, i just got lazy (which doesn't make a better developer out of me i guess).
|
|
|
|
|
|
thanks so much for the link, it helped alot!
|
|
|
|
|
odesh wrote: can anyway shed some light ?
Class B needs a using statement.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hello friends,
I have one question n my question is... How i can read data from .txt file.I have one drawing in autocad which contain all loop name as a text.If i will click on any looptext name then it will open that page..
I have file.. name is "WG_LL.txt" file at particular location.Following data are containing inside my file.
L 10011LoopO\00000001\00000001\00000001.xml
L 400142LoopO\00000001\00000008\00000042.xml
NP10033LoopO\00000001\00000001\00000003.xml
T 10022LoopO\00000001\00000001\00000002.xml
If i will click L 1001 from the Autocad drawing then it will open
" L 10011LoopO\00000001\00000001\00000001.xml" file..I know we can use "shellexecute" to open the document but i dont know how to read data.
Plz any body know then help me bcz i am new in this field..
Thanking u very much.
shah
|
|
|
|
|
Here a code snippet that might help you:
<code>
HANDLE hFile;
DWORD dwNumRead;
BOOL bTest;
char dwBuffer[256];
hFile = CreateFile("File1.txt", GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
bTest= ReadFile(hFile, dwBuffer, sizeof(char)*256, &dwNumRead,NULL);
char seps[] = "\n\r";
char *token;
char *Lines[10];
for (int i=0;i<10;i++)
{
Lines[i] = NULL;
}
token = strtok( dwBuffer, seps );
int x = 0;
while( token != NULL )
{
Lines[x] = token;
token = strtok( NULL, seps );
x++;
}
</code>
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
« Programm3r » wrote: The only programmers that are better than C programmers
*grin* It's possible he's using C, in which case your sample is very useful. If he's using C++, I'd strongly advise against using C file handling.
Christian Graus - C++ MVP
|
|
|
|
|