Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1000
  • Last Modified:

CreateThread wont work in 64bit win 7

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
nchannon
Asked:
nchannon
  • 3
  • 2
  • 2
1 Solution
 
ZoppoCommented:
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
 
nchannonAuthor Commented:
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
 
sarabandeCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ZoppoCommented:
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
 
nchannonAuthor Commented:
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
 
sarabandeCommented:
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
 
nchannonAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now