'initializing' : cannot convert from 'void *' to 'int *'

This is a discussion on 'initializing' : cannot convert from 'void *' to 'int *' within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I can someone tell me why I get this error? I tried to run a source code for the ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    12

    'initializing' : cannot convert from 'void *' to 'int *'

    Hello, I can someone tell me why I get this error? I tried to run a source code for the WINAPI for a program tutoriol, the one I posted in another post. it gives me the error in the title. What could it be? "cannot convert from void * to INT*"?

    The source code for the tutoriol works when I downloaded it. so I don't know why it does that.

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Can you post the source code that is causing errors?
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    If you are using a c++ compiler that error usually means you have to typecast the return value of a function that is returning void*. But can't be certain because we can't see your code and I'm not going to hunt all over this board to try and find the code you previously posted.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    12
    Code:
    case IDC_REMOVE:
    				{
    					// When the user clicks the Remove button, we first get the number
    					// of selected items
    
    					HWND hList = GetDlgItem(hwnd, IDC_LIST);
    					int count = SendMessage(hList, LB_GETSELCOUNT, 0, 0);
    					if(count != LB_ERR)
    					{
    						if(count != 0)
    						{
    							// And then allocate room to store the list of selected items.
    
    							int i;
    							int *buf = GlobalAlloc(GPTR, sizeof(int) * count);
    							SendMessage(hList, LB_GETSELITEMS, (WPARAM)count, (LPARAM)buf);
    							
    							// Now we loop through the list and remove each item that was
    							// selected.  
    
    							// WARNING!!!  
    							// We loop backwards, because if we removed items
    							// from top to bottom, it would change the indexes of the other
    							// items!!!
    
    							for(i = count - 1; i >= 0; i--)
    							{
    								SendMessage(hList, LB_DELETESTRING, (WPARAM)buf[i], 0);
    							}
    
    							GlobalFree(buf);
    						}
    						else 
    						{
    							MessageBox(hwnd, "No items selected.", "Warning", MB_OK);
    						}
    					}
    					else
    					{
    						MessageBox(hwnd, "Error counting items :(", "Warning", MB_OK);
    					}
    				}
    I hope it's not too confusing as I don't really know how to post the coder and in what way you want it. Thanks for ur help

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    int *buf = GlobalAlloc(GPTR, sizeof(int) * count);
    That is valid in C but not C++. In C++, you would need to cast the GlobalAlloc return as an int* like:

    Code:
    int *buf = (int*) GlobalAlloc(GPTR, sizeof(int) * count);
    However if no C++ dependent things reside in the code, I would simply make it a C project.

  6. #6
    Registered User
    Join Date
    May 2005
    Posts
    12
    thanks, it worked. Now i have another problem:

    Code:
    	case WM_CREATE:
    		{
    			HFONT hfDefault;
    			HWND hEdit;
    
    			hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
    				WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 
    				0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
    			if(hEdit == NULL)
    				MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
    
    			hfDefault = GetStockObject(DEFAULT_GUI_FONT);
    			SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    		}
    		break;
    '=' : cannot convert from 'void *' to 'struct HFONT__ *'
    Conversion from 'void*' to pointer to non-'void' requires an explicit cast

    That's from another tutoriol, would i do something diffrent? or the same thing?

  7. #7
    Registered User
    Join Date
    May 2005
    Posts
    12
    Hmmmmm, the controls program compiled fine but wont open for some reason. This is strange. No idea why it wont open

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  4. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  5. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 03:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21