?
Solved

CreateThread wont work in 64bit win 7

Posted on 2014-03-05
8
Medium Priority
?
936 Views
Last Modified: 2014-03-10
Hi can someone show me what needs to be changed to make CreateThread work in 64bit windows OS. I am trying to port my 32bit application to 64bit. Currently my Handle in 64bit is returning NULL I understand I think that under 32bit the data is 8bit aligned and in 64bit it is 16bit aligned but im not sure how to implement CreateThread to work with 16bit aligned any code samples would be great
Thanks
0
Comment
Question by:nchannon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
8 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 39906063
Hi nchannon,

usually there's nothing special about using CreateThread in a 64-bit application.

IMO data alignment shouldn't be an issue here as long as you don't use any wrong casts. BTW: the data alignment is 4 bytes in a 32 bit environment and 8 bytes in a 64 bit environment (found at http://www.codeproject.com/Articles/526984/bit-vs-bit-memory)

Could you post some relevant parts of your code? Especially the signature of your thread function and the part where you call CreateThread?

ZOPPO
0
 

Author Comment

by:nchannon
ID: 39906254
Hi ZOPPO,
This is the code that is used to create the threads THREADCOUNT is 3 currently under 32bit g_hThread gets assigned a value but under 64bit NULL or 0 is assigned
//== Start Thread ==//
void CSocketClass::StartThread()
{
   DWORD threadID;
   for(int n=0;n<THREADCOUNT;n++)
     {
        g_hThread[n]=(HANDLE)CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ProcessThread,NULL,NULL,&threadID);
     }
	
}

Open in new window

0
 
LVL 35

Expert Comment

by:sarabande
ID: 39906675
you should call GetLastError to find out what goes wrong. the error codes you can find in winerror.h.

writing an application for a 64-bit os is not the same as writing a 64-bit application.

in visual studio configuration manager you need to switch the solution platform from WIN32 to x64. if the x64 is not available in the combobox, the installation of visual studio didn't include the 64-bit part or the edition doesn't support it.

(LPTHREAD_START_ROUTINE)ProcessThread
normally it is not so good an idea to cast the thread function. it is much better to use a thread function which already has the correct signature and therefore could be used without cast.

Sara
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 31

Accepted Solution

by:
Zoppo earned 1500 total points
ID: 39906677
Hm - this code IMO looks ok. And you say the same code works fine with 32 bit, right?

Hard to say what's going on there. do you think you could a.) post the declaration of ProcessThread and b.) check the return value GetLastError by adding something like this directly after the line 8 which calls CreateThread:

   TRACE( "CreateThread returned 0x%x, last error is %d\n", g_hThread[n], GetLastError() );

ZOPPO
0
 

Author Comment

by:nchannon
ID: 39915734
Hi yes the code is correct I found the problem it wasn't the code its self but visual studio 10 in 64bit debug mode not behaving correctly which I do not know why and though me out completely. Basically what VS is doing in 64bit mode is it goes into every line of code even if it is not meant to and returns false values giving you the impression there an error in your code but in 32bit debug mode the debugger behaves correctly. I have the thread working fine in 64bit mode now but I must use the 32 debug version to debug correctly do you know why VS 10 behave this way in 64bit debug mode as it is useless what it is doing
0
 
LVL 35

Expert Comment

by:sarabande
ID: 39916431
hmm. in vs2010 debugger 32-bit there is a bug like the one you described. if an if condition does not hit and you step forward, the debugger seems to step into the first line of the if block nevertheless. but actually it is not in the if block but outside the block what you could see by the fact that the variables in the if block were not watchable.

I don't know whether that is the phenomena you experienced, but if so, it is not a 64-bit only bug.

Sara
0
 

Author Comment

by:nchannon
ID: 39917160
Yes very similar thing happening in the 64bit version I guess its a typical Microsoft flaw I ll check it in VS 2012 see if it behaves the same
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question