473,378 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Conversion from LPVOID to HANDLE[] Win32/c++

RedSon
5,000 Expert 4TB
Hi all,

Expand|Select|Wrap|Line Numbers
  1. HANDLE hnd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, (LPVOID)handleArray, 0, &dwThread);
  2.  
  3. ...
  4.  
  5. DWORD ThreadProc(LPVOID lpParameter)
  6. {    
  7.  
  8. HANDLE hArray[NUM_EVENTS];
  9. hArray = (HANDLE)&lpParameter;
  10.  
  11. ...
  12.  
Error is cannot convert from HANDLE to HANDLE[1]. I know it has something to do with the cast that I have there on that second line of the ThreadProc but, for the life of me, I cannot figure out how to get it right.

Thanks in advance!
Jan 9 '07 #1
5 4572
Banfa
9,065 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. /* I am guessing this */
  2.     HANDLE handleArray[NUM_EVENTS];
  3.  
  4.     HANDLE hnd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, 
  5. /* At this point we have a pointer of type HANDLE * and 
  6.    cast it to LPVOID */
  7.                    (LPVOID)handleArray, 0, &dwThread);
  8.  
  9. ...
  10.  
  11. DWORD ThreadProc(LPVOID lpParameter)
  12. {    
  13.  
  14.     HANDLE hArray[NUM_EVENTS];
  15.  
  16. /* 
  17.   1.  hArray is of type HANDLE [NUM_EVENTS], i.e. an array 
  18.       but the cast is to type HANDLE
  19.   2.  lpParameter contins a HANDLE * but you take a pointer(&) to 
  20.       it which will just be a pointer to somewhere random on the 
  21.       stack not a pointer to the original array.  The & is not required.
  22.   3.  Attemping to assign a pointer to an array is illegal
  23. */
  24.     hArray = (HANDLE)&lpParameter;
  25.  
  26. ...
  27.  
2 options

1. In the thread use a HANDLE pointer and then just use it like an array
Expand|Select|Wrap|Line Numbers
  1. DWORD ThreadProc(LPVOID lpParameter)
  2. {    
  3.  
  4.     HANDLE *hArray;
  5.     hArray = (HANDLE)lpParameter;
  6. ...
  7. }
  8.  
2. In the thread copy the handles from the pointer to the array
Expand|Select|Wrap|Line Numbers
  1. DWORD ThreadProc(LPVOID lpParameter)
  2. {    
  3.     HANDLE hArray[NUM_EVENTS];
  4.  
  5.     memcpy((void *)hArray, lpParameter, sizeof hArray);
  6. ...
  7. }
  8.  
Jan 9 '07 #2
RedSon
5,000 Expert 4TB
You know I think I got confused because in that Thread Proc I am using a method called MsgWaitForMultipleObjects which needs an array of object handles. I'll go with option 1 since it's simple.

Thanks for the help!
Jan 9 '07 #3
RedSon
5,000 Expert 4TB
2 options

1. In the thread use a HANDLE pointer and then just use it like an array
Expand|Select|Wrap|Line Numbers
  1. DWORD ThreadProc(LPVOID lpParameter)
  2. {    
  3.  
  4.     HANDLE *hArray;
  5.     hArray = (HANDLE)lpParameter;
  6. ...
  7. }
  8.  
That is almost right...still a type mismatch

Expand|Select|Wrap|Line Numbers
  1.  
  2. DWORD ThreadProc(LPVOID lpParameter)
  3. {    
  4.  
  5.     HANDLE *hArray;
  6.     hArray = (HANDLE*)lpParameter;
  7. ...
  8. }
  9.  
No worries, compiler caught it straight away and complained about it. Easy fix too. :D
Jan 9 '07 #4
Banfa
9,065 Expert Mod 8TB
So? Even experts like me can still make typing mistakes :D
Jan 9 '07 #5
RedSon
5,000 Expert 4TB
Sure, sure... "a typing mistake" LOL :D
Jan 9 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: PyTJ | last post by:
Hello everybody, I need to convert a Japanese Shift-JIS CSV file to Unicode UTF-8. My machine is a Windows 98 english computer with Python 2.3.4 Any hints?.
4
by: Fred Heida | last post by:
Hi All, maybe this is a sill question..but if i have TextBox and use the SendMessage(..) to send a character the control.. the KeyDown event is not triggered.... in would need to check in the...
6
by: Thomas Barth | last post by:
Hi, I'm new to windows programming and still reading a book about windows-programming with C++. I copied the following code from the book into my ide (Eclipse/CDT) to comprehend the code, but two...
9
by: bclegg | last post by:
Hi, I am a VB.net programmer who has to make use of a 3rd party Borland C++ dll. We have a successful VC++ wrapper that presents a number of functions that can be declared and called in VB.net ...
1
by: LongBow | last post by:
Hello, I am attempting to create an application that uses an existing driver interface API using C#. I have an API that looks like F32x_Read( HANDLE Handle, LPVOID Buffer, DWORD...
7
by: Russell Mangel | last post by:
I have been doing some C++ Interop using the new VS2005 (June Beta). I am exposing these methods to .NET clients. I ran into some WinAPI methods which use LPVOID types, and I don't understand...
7
by: Ken Varn | last post by:
I am working in managed C++. I have a Mutex object in which I need to replace the Handle property with a new handle. The new handle is being constructed using Win32 CreateMutex call. I need to...
7
by: guy | last post by:
Has anyone any experience of the conversion wizard for VB6 to VB2005? if so how good is it? also how does it handle database related conversions i.e is ADO converted to ADO.NET etc. the project...
4
by: ppuniversal | last post by:
Hello, I am making a thread program, in which i call : hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)(this->runThread), this, 0, &ThreadId);
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.