|
Dear all,
I'm writing a small application that manages the Themes service using WMI.
Unfortunately I have problems with the parameters. The API documentation says that it is a string, but I wasn't able to find a solution.
ExecMethod returns : WBEM_E_INVALID_METHOD_PARAMETERS = 0x8004102f
I have realized that the parameter is not well formatted, but I'm not able to find any tip.
Notice that the same code querying for "Win32_Process" and calling "Create" using CommandLine as parameter and "notepad.exe" as value, runs correctly. To test it, it is enough to replace the strings text.
Thanks
Daniele
// some WMI initialization here.....
IWbemClassObject *pClass = NULL;
IWbemClassObject *pInParams = NULL;
IWbemClassObject *pInParamInstance = NULL;
IWbemClassObject *pOutParams = NULL;
IEnumWbemClassObject *pEnumerator = NULL;
IWbemClassObject *pInstance = NULL;
DWORD dwCount = 0;
HRESULT hres;
BSTR bstrChangeStartMode = L"ChangeStartMode";
BSTR bstrClassName = L"Win32_Service";
BSTR bstrParamName = L"StartMode";
BSTR bstrParamValue = L"Automatic";
VARIANT varValue;
VARIANT varReturnValue;
// query for the proper object to which apply the method
hres = pSvc->ExecQuery( bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Service Where Name = 'Themes'"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
while (pEnumerator->Next( WBEM_INFINITE, 1,&pInstance, &dwCount) == WBEM_S_NO_ERROR)
{
// get method class
hres = pSvc->GetObject( bstrClassName, 0, NULL, &pClass, NULL);
// prepare method params
if (pClass)
hres = pClass->GetMethod(bstrChangeStartMode,0,&pInParams,NULL);
else
{
printf("Unable to get method '%s' from '%s' class\n", CString(bstrChangeStartMode), CString(bstrClassName));
return -1;
}
if (pInParams)
hres = pInParams->SpawnInstance(0, &pInParamInstance);
else
{
printf("Unable to get params for from %s::%s()\n",
CString(bstrClassName),
CString(bstrChangeStartMode));
return -2;
}
// analyzing the method paramenter (debug purposes only)
printf("Analyzing the %s::%s() paramenter(s)...\n",
CString(bstrClassName),
CString(bstrChangeStartMode));
hres = pInParams->BeginEnumeration(0);
BSTR pName = NULL;
while ((pInParams->Next(NULL, &pName, NULL, NULL, NULL)) == BEM_S_NO_ERROR)
{
CString s(pName);
printf("Property value: %s\n", s);
}
pInParams->EndEnumeration();
printf("\n");
// Create the values for the in-parameters
VariantInit(&varValue);
varValue.vt = VT_BSTR;
varValue.bstrVal = bstrParamValue;
// assign a value to the option...
if (pInParamInstance)
hres = pInParamInstance->Put( bstrParamName, 0,
&varValue,
0);
else
{
printf("Unable to create params instance for %s::%s()\n",
CString(bstrClassName),
CString(bstrChangeStartMode));
return -3;
}
if (hres != S_OK)
return -4;
// Execute Method
hres = pSvc->ExecMethod(bstrClassName, // class
bstrChangeStartMode, // method
0, // synchronous call NULL, //
pInParamInstance, // input
&pOutParams, // output
NULL);
if (hres != S_OK)
break;
} // end while pEnumerator
if (pEnumerator)
pEnumerator->Release();
} // end query....
if (hres != S_OK)
{
printf("Exec method for %s::%s() returned 0x%08X\n\n",
CString(bstrClassName),
CString(bstrChangeStartMode),
hres);
}
Daniele
|
|
|
|
|
Hi
I have a question,I write this question yesterday but I think that I couldn't that what I need?
see if one page has many links for download we can click in links and download it link
(with classes Chttp,CInternetSession,CHttpConnection,.... or with URLDownloadToFile)
Now if I have to enumerate this links how to do? almost like ftp that enumerate files or directories
Is it possible?
Thanks
|
|
|
|
|
messages wrote: Now if I have to enumerate this links how to do?
Enumerate links? What do you mean by this?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Instead click in each link I want to read this links and then download they see example:
In one page 10 links to pictures,pictures are thubmnail and if we click in this thubm then we can see full picture
but I want without click directly read this files
Is it possible?
Thanks
|
|
|
|
|
messages wrote: Is it possible?
Most likely. Load the HTML page using the IHTMLDocument2 interface, and then iterate each of the Anchor <A> elements. Search for IHTMLElementCollection. Here is another example.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
|
|
Hi Mila025
thank you for link but is there any way to enumerate links
I think that is't not possible.
Thanks
|
|
|
|
|
Hi
One of my friends is getting a strange problem with his code in c++. He has stored some integer values in an array. That array is declared in a class as its member variable.
In a function before printing this array using cout, he wrote the following statement.
cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss\n";
We saw it in Debugger mode that when above statement executes, all values in that array are changed and some garbage values are displayed.
Please can you tell me why this is happening?
Thank you.
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
|
Thank you for your responce. Here is the code
cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss"<<endl;<br />
for(;curr->next!=&head;curr=curr->next)<br />
{<br />
for(;curr->next->array[i].day_number!=-1;i++)<br />
{<br />
cout<<curr->next->array[i].day_number<<"\t"<br />
<<curr->next->array[i].break_up<<"\t"<br />
<<curr->next->array[i].buying_price<<"\t"<br />
<<curr->next->array[i].selling_price<<"\t"<br />
<<curr->next->array[i].capital_gain<<endl;<br />
}<br />
}
I tried this code after omitting the first cout line. but in inner for loop before printing the values again it changes the array contents.
How it is possible?
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
Aqueel wrote: cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss\n";
Use endl instead of \n .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
problem still remains the same
in this block of code if i perform a very very simple output operation (cout<<"Hello"<
|
|
|
|
|
Here is the whole code u can copy past into your browser and run it
Note
file inpu.txt has the following format
B 100 20
B 20 24
B 200 36
S 150 30
//code begins from here
#include<iostream.h>
#include<fstream.h>
//*******************************************************************
struct SDATA
{
int day_number;
int break_up;
int buying_price;
int selling_price;
int capital_gain;
};
//*******************************************************************
class QNode
{
friend class Queue;
private:
QNode* next;
int day;
int shares;
int price;
QNode(){next=NULL;}
};
//*******************************************************************
class LLNode
{
friend class LList;
friend class Queue;
friend void main();
private:
LLNode* prev;
LLNode* next;
SDATA array[10];
LLNode()
{
prev=NULL;
next=NULL;
for(int i=0;i<10;i++)
{
array[i].day_number=-1;
array[i].break_up=-1;
array[i].buying_price=-1;
array[i].selling_price=-1;
array[i].capital_gain=-1;
}
}
};
//*******************************************************************
class Queue
{
private:
QNode* front;
QNode* rear;
public:
Queue(){front=rear=NULL;};
bool Enqueue(ifstream&);
bool Dqueue(LLNode*, int, int&);
void dis();
};
//*******************************************************************
class LList
{
friend void main();
private:
LLNode head;
public:
LList()
{
head.next=&head;
head.prev=&head;
};
bool add(ifstream&, Queue);
void Display();
};
int dy=1;
//*******************************************************************
//*******************************************************************
bool Queue::Enqueue(ifstream& fin)
{
int shs;
int pr;
fin>>shs;
fin>>pr;
fin.get();
QNode* temp=new QNode();
temp->day=dy;
temp->price=pr;
temp->shares=shs;
if(front==NULL)
{
front=temp;
rear=temp;
rear->next=NULL;
return true;
}
else
{
rear->next=temp;
rear=rear->next;
rear->next=NULL;
return true;
}
delete temp;
}
//*******************************************************************
void Queue::dis()
{
QNode* curr;
curr=front;
int dy,pr,sh;
for(;curr!=NULL;curr=curr->next)
{
dy=curr->day;
pr=curr->price;
sh=curr->shares;
cout<<dy<<" "<<pr<<"="" "<<sh<<endl;
="" }
="" cout<<endl;
}
="" ********************************************************************
bool="" llist::add(ifstream&="" fin,="" queue="" q)
{
="" int="" sell_shares;
="" sell_price;
="" tot="0;
" llnode="" temp;
="" fin="">>sell_shares;
fin>>sell_price;
fin.get();
q.Dqueue(&temp,sell_shares,tot);
for(;tot>=0;tot--)
{
temp.array[tot].selling_price=sell_price;
temp.array[tot].capital_gain=(temp.array[tot].break_up*(sell_price-temp.array[tot].buying_price));
//******************
/*mret->array[tot].day_number=temp.array[tot].day_number;
mret->array[tot].buying_price=temp.array[tot].buying_price;
mret->array[tot].selling_price=temp.array[tot].selling_price;
mret->array[tot].break_up=temp.array[tot].break_up;
mret->array[tot].capital_gain=temp.array[tot].capital_gain;*/
}
LLNode* curr;
curr=&head;
while(curr->next!=&head)
curr=curr->next;
temp.next=curr;
temp.prev=curr->prev;
curr->prev->next=&temp;
curr->prev=&temp;
//************************************************************
{
curr=&head;
cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss\n";
for(;curr->next!=&head;curr=curr->next)
{
for(int i=0;temp.array[i].day_number!=-1;i++)
{
cout<<temp.array[i].day_number<<"\t"
<<temp.array[i].break_up<<"\t"
="" <<temp.array[i].buying_price<<"\t"
="" <<temp.array[i].selling_price<<"\t"
="" <<temp.array[i].capital_gain<<endl;
="" }
=""
="" return="" false;
}
="" ********************************************************************
bool="" queue::dqueue(llnode*="" temp,int="" sell_shares,="" int&="" ret)
{
="" int="" sum="0;
" qnode*="" curr;
="" curr="front;
" count="sell_shares;
" for(int="" i="0;i<10&&curr!=NULL;i++)
" {
="">shares;
curr=curr->next;
}
curr=front;
if(sell_shares>sum)
{
cout<<"\nYOU ARE TRYING TO SELL SHARES OF MORE"<<endl;
cout<<"than="" last="" 10="" days..."<<endl;
="" return="" false;
="" }
="" else
="" {
=""
="" if(front="=NULL)" for(ret="0;count">0;ret++)
{
if(count<front->shares)
{
temp->array[ret].day_number=front->day;
temp->array[ret].buying_price=front->price;
temp->array[ret].break_up=count;
front->shares=front->shares-count;
count=0;
}
else if(sell_shares>=front->shares)
{
temp->array[ret].day_number=front->day;
temp->array[ret].buying_price=front->price;
temp->array[ret].break_up=front->shares;
count=count-front->shares;
front=front->next;
delete curr;
curr=front;
}
}
ret--;
return true;
}
}
}
//********************************************************************
void LList::Display()
{
LLNode* curr;
curr=&head;
int i=0;
cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss"<<endl;
for(;curr-="">next!=&head;curr=curr->next)
{
for(;curr->next->array[i].day_number!=-1;i++)
{
cout<<curr->next->array[i].day_number<<"\t"
<<curr->next->array[i].buying_price<<"\t"
<<curr->next->array[i].break_up<<"\t"
<<curr->next->array[i].selling_price<<"\t"
<<curr->next->array[i].capital_gain<<endl;
}
=""
}
="" ********************************************************************
void="" main()
{
="" llnode="" temp;
="" queue="" q;
="" llist="" l;
="" char="" op;
="" ifstream="" fin;
="" fin.open("input.txt",ios::in);
="" fin="">>op;
while(!(fin.eof()))
{
if(op=='B')
{
for(;op=='B'&&(!fin.eof());)
{
Q.Enqueue(fin);
fin>>op;
dy++;
}
}
else if(op=='S')
{
for(;op=='S'&&(!fin.eof());)
{
L.add(fin,Q);
dy++;
fin>>op;
}
}
}
//Q.dis();
L.Display();
}
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
Strange. It should not happen this way.
Problem might lie before the cout statement.
As you said even if you write cout<<"Hello" it overwrites the array.
I would suggest to do a stepwise debug.
1) comment out all the array allocation and file reading part.
2) just main() -> and cout<<"Hello"
3) check if this works.
4) if it does then uncomment file readin part.
5) if tht works then problem lies somewhere in the array allocation part.
Hope this helps.
|
|
|
|
|
Hi all,
In my MDI application, I have 10 tool bars. I have a menu to select them. If it is visible, its menu item would be checked. I need to save the position of those tool bars when I exit the application. Next time I should be able to get toolbars, only which were selected earlier. Hope it's like persistent window concept. But I don't know how to make it possible for Toolbars.
If anybody could suggest me a path, it would be greatly appreciated.
Thanks in advance,
Sarvan AL
|
|
|
|
|
#ifdef EXPCLASS_EXPORTS
#define EXPCLASS_API __declspec(dllexport)
#else
#define EXPCLASS_API __declspec(dllimport)
#endif
// This class is exported from the EXPCLASS.dll
class EXPCLASS_API CEXPCLASS {
public:
CEXPCLASS(void);
char * CEXPMethod(char * plaintext , char * key);
// TODO: add your methods here.
};
How do i dynamically acces method export in CLASS?
CODE USED TO ACCESS METHOD EXPORT IN CLASS
hDLL = LoadLibrary("EXPCLASS.dll");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"CEXPMethod");
if (lpfnDllFunc1 ==NULL)
{
// handle the error
FreeLibrary(hDLL);
}
else
{
strResult = lpfnDllFunc1("killer" ,"strikes HERE");
}
}
for thendral
-- modified at 6:54 Thursday 20th April, 2006
|
|
|
|
|
|
Hi naveen !
can u advise what exactly i need to do ?
Use this API to get the address of a function that returns an instance of the class that you wish to access dynamically.
For eg:
The function will be something like this...
void* FUNC_EXPORT CreateInstance()
{ return static_cast< void*> (new SomeClass);
}
Use GetProcAddress to get the address of this function
for thendral
|
|
|
|
|
instead of returning the void* u can return the pointer to the class
say
SomeClass* FUNC_EXPORT CreateInstance()
{ return static_cast< void*> (new SomeClass);
}
them u can access the functions of that clas using the pointer obtained..
nave
|
|
|
|
|
Iam not in control of the situation.
Can i have a sample code that achieves it?
class __declspec(dllexport) MyClass
{
public:
static char* LSGDecrypt(const char* key,const char* hex);
static char* LSGEncrypt(const char* key,const char* source);
}
The above class is export in a dll .
So should i add new function to the dll ?
Iam about access a static function
So is that required to instantiate the class object.
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
char* key = new char [50];
key ="KEYVAULE";
char* strPlain = new char [50];
strPlain="password";
char* strResult = new char [50];
DWORD dwrd =NULL;
hDLL = LoadLibrary("Mydll.dll");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"LSGEncrypt");
if (lpfnDllFunc1 ==NULL) // Fails here? so DLL is freed up?
{
FreeLibrary(hDLL);
}
else
strResult = lpfnDllFunc1("killer" ,"strikes HERE");
}
Thanks
for thendral
|
|
|
|
|
Hi All,
Can anyone suggest me how to capture Desktop and record it?
Thanks in advance,
Poornima
|
|
|
|
|
what u want is to take a screen shot of the desktop and save it as bitmap.. just search on the code project..u will find many samples
nave
|
|
|
|
|
hi all,
I want to change the selected Full Row of the MSFlexGrid accordingly when mouse changes its cursor to next Row. I mean when Mouse is moved to the Second Row then the Current Selection must be Second Row.
In general the Selection of the Flex Grid is Static and does not depend on the Mouse Move. please help me out for this solution.
thanks,
uday.
uday kiran
uday kiran
|
|
|
|
|
Hi all,
I know I can use PlgBlt to rotate a defined rectangle, but i am not sure on how to use it properly, meaning i want to rotate a drawn rectanle (a rectangle which is drawn on a dialog using the method OnPaint) in 30 degrees.
The question is how to maintain the drawing, for example to to erase the old rectangle place, and how to draw the new rectangle place using the PlgBlt method...
code snippet could be nice
thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|