|
CreateThread() has a param just for this purpose: void* lpParameter . Set that to the address of the Wmi object. loadPerThrdFunc takes one parameter, again a void* , which you cast back to a WmiWrapper*
Note that you should be using _beginthreadex() and not CreateThread() if you link with the C runtime (which you probably are)
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Windows troubleshooting: Reboot first, ask questions later.
|
|
|
|
|
Did some modification in your existing code. This would help you.
For the passing parameter to thread, first cast it to DWORD and receive it in callback handler of thread,cast it back to its original type,now use it as you want.
void main(void){
DWORD loadPerThrdID;
HANDLE loadPerThrd;
TCHAR szMsg[80];
DWORD dwThrdParam;
static WmiWrapper Wmi(NULL, NULL, NULL); //Creating object
loadPerThrd = CreateThread(
NULL, 0,
loadPerThrdFunc,
//&dwThrdParam,
(DWORD) &Wmi, //Pass the object pointer as a thread parameter.
0, &loadPerThrdID);
if(loadPerThrd == NULL){
wsprintf(szMsg, (TEXT("Create Thread failed for LoadPercentage")));
MessageBox(NULL, szMsg, NULL, MB_OK);
}
else{
_getch();
CloseHandle(loadPerThrd);
}
}
//Threads function
DWORD WINAPI loadPerThrdFunc (DWORD param1)
{
WmiWrapper* wmi = (WmiWrapper*) param1;
//Now you can use this wmi class pointer.
................
}
Jitendra
|
|
|
|
|
No good,
First I think the WmiWrapper* is 64 bits, where as DWORD is 32, so this gives me data loss warnings,
Also the parameter is LPTHREAD_START_ROUTINE , not DWORD , so this gives me an error.
Its alright because I have it fixed (see David Crows code above), but now Im getting a memory voilation when running, and its in one of the classes methods, I dont understand, because I was running the program without threads before and I didnt get this problem, I thought mabey it has something to do with the fact that Im creating two threads which pass the same object, but if I turn off one I still get the error
We have a mathematician, a different kind of mathematician, and a statistician!
|
|
|
|
|
The 'WmiWrapper*' can only be 64 bits if you're compiling for 64 bit Windows. You would know this.
I think you get the warning because MS have made the SDK headers 64 bit compatible and introduced some new MS special bits to allow this. In the future a DWORD won't be compatible with a pointer.
Anyway the parameter to CreateThread is 'LPVOID' not DWORD so in 64bit Windows that will be a 64 bit pointer and all will just work.
Anyway I would expect something like
DWORD WINAPI loadPerThrdFunc ( LPVOID param )
{
WmiWrapper* wmi = reinterpret_Cast<WmiWrapper*>( param );
}
loadPerThrd = CreateThread (
NULL,
0,
loadPerThrdFunc,
&Wmi,
0,
&loadPerThrdID);
Paul
|
|
|
|
|
That is all right.Thanks for correcting me.
The memory violation that you are facing may be due to that you are creating a local object.when you are creating the thread and passing the pointer of it. but after creation of thread, the control come back in the main function and the local object will got out of scope.still the thread is running and trying to access it by the pointer and cause the memory violation. if this is a problem then you can allocate the object by 'new' operator. so when you don't want it you can deallocate it manually.
Jitendra
|
|
|
|
|
i need to get the ip of the machine my code is running on..
how can i program that ?
thanx
shakoosh
|
|
|
|
|
Call gethostname() followed by gethostbyname() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
you can list all your IP Addresses by doing this :
<font style="color:blue;">struct</font> hostent* infohost;
<font style="color:blue;">char</font> HostName[256];
<font style="color:blue;">char</font>** addrs;
<font style="color:blue;">char</font>* Host;
gethostname(HostName, 255);
Host = HostName;
infohost = gethostbyname(HostName);
addrs = infohote -> h_addr_list;
<font style="color:blue;">while</font> (*addrs) {
printf("IP : %s\n", inet_ntoa( *(struct in_addr *)* addrs));
addrs++;
}
don't forget to check errors.
Your main IP Address while being in a TCP network is in general the first, but not necessarily...
TOXCCT >>> GEII power
|
|
|
|
|
<br />
#include "stdafx.h"<br />
#using <mscorlib.dll><br />
#using <System.Windows.Forms.dll><br />
using namespace System;<br />
using namespace System::Windows::Forms;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
String* hostName = SystemInformation::ComputerName;<br />
System::Net::IPHostEntry* hostEntry = System::Net::Dns::GetHostByName(hostName);<br />
Console::WriteLine(S"Host name : {0}", hostEntry->HostName);<br />
for (System::Int32 i = 0; i < hostEntry->AddressList->Length; ++i)<br />
{<br />
Console::WriteLine(hostEntry->AddressList->Item[i]);<br />
}<br />
return 0;<br />
}<br />
Sincerely,
-Ron
|
|
|
|
|
Or, if you don't like console output:
<br />
#include "stdafx.h"<br />
#using <mscorlib.dll><br />
#using <System.Windows.Forms.dll><br />
using namespace System;<br />
using namespace System::Windows::Forms;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
#pragma push_macro("new")<br />
#undef new<br />
String* hostName = SystemInformation::ComputerName;<br />
System::Net::IPHostEntry* hostEntry = System::Net::Dns::GetHostByName(hostName);<br />
for (int i = 0; i < hostEntry->AddressList->Length; ++i)<br />
{<br />
Text::StringBuilder* sb = new Text::StringBuilder();<br />
sb->Append(hostName);<br />
sb->AppendFormat(S" IP Address {0} = ", __box(i));<br />
sb->Append(hostEntry->AddressList->Item[i]->ToString());<br />
MessageBox::Show(sb->ToString());<br />
}<br />
return 0;<br />
#pragma pop_macro("new")<br />
}<br />
Sincerely,
-Ron
|
|
|
|
|
I got a question regarding storing of settings in the registry.
My application continously stores settings in the registry during runtime, before each value is saved I open the specific registry key and after the value is saved operation i close it.
This causes a frequent opening and closing of a specific registry key.
Is it more suitable for my application to open the registry key at start and to close the key whenever my application is due to shut down? Will there be somekind of vulnerability/benefit using this method, which one is prefered?
|
|
|
|
|
If you have a bunch of open/write/close calls, you might notice a small performance hit, if any, but you must weigh that against the registry cache not being flushed if your application were to terminate abnormally. The registry API does not necessarily write information to the registry immediately; it can take as much as several seconds for the cache to be flushed to the hard disk.
Microsoft Outlook hits the registry about once every 1-2 seconds, with a call to RegCloseKey() each time.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi,
I am very new in windows programming but i want to do something to may be strange.
I want to build an application-Web Browser (or somehow extend the functionality of IE (plugin)) that in every request browser makes adding two additional headers.
for example: a request that makes IE is
GET http://www.google.com.gr/ HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-
powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwav
e-flash, */*
Accept-Language: el
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705
; .NET CLR 1.1.4322)
Host: www.google.com.gr
Proxy-Connection: Keep-Alive
I want to add two more headers(at the end):
Profile: "http://139.91.70.5/index.html1","1-]Ό╓π╦^◄_ϊ~N<°;╪║"
Profile-Diff-1: <rdf xmlns="http://www.w3.org/TR/1999/PR
-rdf-syntax-19990105#" xmlns:prf="http://www.w3.org/TR/WD-profile-vocabulary#">
<description about="Hardware"> <modifications>
a)Can i change every request that IE makes enhance it with a plugin that doing that(adding the two headers)..?
b)Can i build an application from the scratch reusing the Web Browser Control (for the the HTML parsing and rendering of the sites) and enhance my_application with this functionality i describe above..?
c)I also saw in the MSDN documentation something about Winlnet (CHTTPSESSION), but i don't know if i can use such a think.(if i am able to use it, can i change the request that leaves from my client(adding the headers) and can i parse and render the html site that the server will return to my_client and present it properly?)
Does anybody knows anything else i can do..??
Please help me...
Thanks in advance!!!
Manos Moschous
|
|
|
|
|
I have a MFC application with a COM interface. When I start the application via COM (i.e. a vbscript) its user interface is blocked until the call has returned. Is there any way to work around this problem?
|
|
|
|
|
|
How do I do that????
We have a mathematician, a different kind of mathematician, and a statistician!
|
|
|
|
|
No cast is necessary:
int i = 12345;
unsigned int ui = i;
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
The plugin´s name?
Quotation "I forgot the name of it, but there is a compiler plugin for VC++ that distributes the compiling across the network, so that build times are near zero, with only linking occuring at the requester. I recall hearing about game companies using it for their massive builds, diminishing hour long builds to less than a minute."
Gywox
|
|
|
|
|
I cannot remember how you make any new document inside an MDI app maximized by default...
I want the window to default to maximized state I do not want to set it to maximized state inside some function like:
CView::OnInitialUpdate() and call
CChildFrame* pFrame = (CChildFrame*)GetParentFrame();
pFrame->MDIMaximize();
All these techniques still cause serious flicker when opening new windows...or navigating...
Is this possible?
TIA
How do I print my voice mail?
|
|
|
|
|
Override PreCreateWindow() in your child frame class and make sure cs.style includes WS_MAXIMIZE .
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
There is a SDI app that I want to shut down after 1 second (it's a frame capture app).
I have tried PostMessage but haven't been able to figure it out yet.
Does anyone have a suggestion ?
Ta.
Elaine
The tigress is here
|
|
|
|
|
PostMessage(WM_CLOSE, 0, 0);
|
|
|
|
|
Yes, but where in the application, remembering that I will need to start a timer ?
The tigress is here
|
|
|
|
|
Check Sleep
or call SetTimer, and you will receive a message WM_TIMER that you need to handle
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I'm trying to modify the style(CBS_SORT) of a combo box control inside a dialog box at run time. Its seems its not updating? I added the ModifyStyle function inside the InitDialog of the Dialogbox. Is there something I'm missing?
Thanks
|
|
|
|