Void* return

Aug 29, 2011 at 10:58am
Hi, what i can use for return on Void*

I have func:

1
2
3
4
5
6
7
8
9
10
11
12
13
void* RegistryRead_VersionEditor() // Version of Editor
{
	char VERSION[1024];
	HKEY hKey;
	DWORD t,s;
	LONG l;
	s = 1023;
	l = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\World of Warcraft",0,KEY_QUERY_VALUE,&hKey);
	l = RegQueryValueEx(hKey,"VersionLauncher",0,&t,(LPBYTE)VERSION,&s);
	RegCloseKey(hKey);

	return 0;
}


Why * ? Because i use it for converting Void* to Char* to System::String i using Windows Form ( I doing launcher )

Thank for help.
Aug 29, 2011 at 11:37am
You can use a void*. Either work out what it is that you actually want to return, or if you don't want to return anything and can't change the function prototype, you can just create a void pointer and return it:

1
2
void* dummyPointer;
return dummyPointer;

Aug 29, 2011 at 12:46pm
Seriously though, there is nothing to return here except maybe the hKey variable but you close that handle on Line 10. Do you know what you're trying to do, or are you copying this from another source?
Aug 29, 2011 at 1:00pm
I code it. But i read on network, i need Void change to Void* for convertation to char*
Moschops...i use it and receive error:
1
2
1>c:\programovani\wow editor\test\src\launcher\Form1.h(357): error C2440: 'return' : cannot convert from 'void *(__clrcall WorldofWarcraftEditorLauncher::Form1::* )(void)' to 'void *'
1>          There is no context in which this conversion is possible


error C3867: 'WorldofWarcraftEditorLauncher::Form1::RegistryRead_VersionEditor': function call missing argument list; use '&WorldofWarcraftEditorLauncher::Form1::RegistryRead_VersionEditor' to create a pointer to member
Last edited on Aug 29, 2011 at 1:09pm
Aug 29, 2011 at 1:16pm
As the function stands, you're always returning a null pointer (replacing 0 with NULL would change nothing).

Declaring an uninitialized void* pointer variable and returning it would be worse, as the address could be anywhere. And initializing it to 0/NULL would be the same as returning 0.

But your comment suggests you want to return the value (the VERSION) as a System::String. So why not just return a String^ using String^ retstr = gcnew String(VERSION); ??

That is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
String^ RegistryRead_VersionEditor_2() // Version of Editor
{
	char VERSION[1024] = {0};
	HKEY hKey;
	DWORD t,s;
	LONG l;
	s = 1023;
	l = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\World of Warcraft",0,KEY_QUERY_VALUE,&hKey);
	l = RegQueryValueEx(hKey,"VersionLauncher",0,&t,(LPBYTE)VERSION,&s);
	RegCloseKey(hKey);

	String^ retstr = gcnew String(VERSION);
	return retstr;
}


Andy

P.S. I would adjust your code so it handles errors correctly.
Last edited on Aug 29, 2011 at 1:18pm
Aug 29, 2011 at 1:53pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void* RegistryRead_VersionEditor() // Version of Editor
{
	char VERSION[1024];
	HKEY hKey;
	DWORD t,s;
	LONG l;
	s = 1023;
	l = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\World of Warcraft",0,KEY_QUERY_VALUE,&hKey);
	l = RegQueryValueEx(hKey,"VersionLauncher",0,&t,(LPBYTE)VERSION,&s);
	RegCloseKey(hKey);

	String^ PRINTVERSION = gcnew String(VERSION);
	return PRINTVERSION;
}


Errror:

error C2440: 'return' : cannot convert from 'System::String ^' to 'void *'
Aug 29, 2011 at 2:33pm
Yes???

Your function header is different to mine!
Last edited on Aug 29, 2011 at 2:33pm
Aug 29, 2011 at 4:27pm
I get error from linker after.. :(


1
2
3
4
5
6
7
8
9
Error	11	error LNK1120: 8 unresolved externals	C:\programovani\WoW Editor\Test\src\Launcher\Bin\Release\World of Warcraft - Editor Launcher.exe
Error	3	error LNK2028: unresolved token (0A000017) "extern "C" long __stdcall RegCloseKey(struct HKEY__ *)" (?RegCloseKey@@$$J14YGJPAUHKEY__@@@Z) referenced in function "private: class System::String ^ __clrcall WorldofWarcraftEditorLauncher::Form1::RegistryRead_VersionEditor(void)" (?RegistryRead_VersionEditor@Form1@WorldofWarcraftEditorLauncher@@$$FA$AAMP$AAVString@System@@XZ)	C:\programovani\WoW Editor\Test\src\Launcher\World of Warcraft - Editor Launcher.obj
Error	4	error LNK2028: unresolved token (0A000054) "extern "C" long __stdcall RegOpenKeyExA(struct HKEY__ *,char const *,unsigned long,unsigned long,struct HKEY__ * *)" (?RegOpenKeyExA@@$$J220YGJPAUHKEY__@@PBDKKPAPAU1@@Z) referenced in function "private: class System::String ^ __clrcall WorldofWarcraftEditorLauncher::Form1::RegistryRead_VersionEditor(void)" (?RegistryRead_VersionEditor@Form1@WorldofWarcraftEditorLauncher@@$$FA$AAMP$AAVString@System@@XZ)	C:\programovani\WoW Editor\Test\src\Launcher\World of Warcraft - Editor Launcher.obj
Error	5	error LNK2028: unresolved token (0A000074) "extern "C" long __stdcall RegQueryValueExA(struct HKEY__ *,char const *,unsigned long *,unsigned long *,unsigned char *,unsigned long *)" (?RegQueryValueExA@@$$J224YGJPAUHKEY__@@PBDPAK2PAE2@Z) referenced in function "private: class System::String ^ __clrcall WorldofWarcraftEditorLauncher::Form1::RegistryRead_VersionEditor(void)" (?RegistryRead_VersionEditor@Form1@WorldofWarcraftEditorLauncher@@$$FA$AAMP$AAVString@System@@XZ)	C:\programovani\WoW Editor\Test\src\Launcher\World of Warcraft - Editor Launcher.obj
Error	6	error LNK2028: unresolved token (0A000078) "extern "C" long __stdcall RegSetValueExA(struct HKEY__ *,char const *,unsigned long,unsigned long,unsigned char const *,unsigned long)" (?RegSetValueExA@@$$J224YGJPAUHKEY__@@PBDKKPBEK@Z) referenced in function "private: void __clrcall WorldofWarcraftEditorLauncher::Form1::Updates_Registry(void)" (?Updates_Registry@Form1@WorldofWarcraftEditorLauncher@@$$FA$AAMXXZ)	C:\programovani\WoW Editor\Test\src\Launcher\World of Warcraft - Editor Launcher.obj
Error	7	error LNK2019: unresolved external symbol "extern "C" long __stdcall RegCloseKey(struct HKEY__ *)" (?RegCloseKey@@$$J14YGJPAUHKEY__@@@Z) referenced in function "private: class System::String ^ __clrcall WorldofWarcraftEditorLauncher::Form1::RegistryRead_VersionEditor(void)" (?RegistryRead_VersionEditor@Form1@WorldofWarcraftEditorLauncher@@$$FA$AAMP$AAVString@System@@XZ)	C:\programovani\WoW Editor\Test\src\Launcher\World of Warcraft - Editor Launcher.obj
Error	8	error LNK2019: unresolved external symbol "extern "C" long __stdcall RegQueryValueExA(struct HKEY__ *,char const *,unsigned long *,unsigned long *,unsigned char *,unsigned long *)" (?RegQueryValueExA@@$$J224YGJPAUHKEY__@@PBDPAK2PAE2@Z) referenced in function "private: class System::String ^ __clrcall WorldofWarcraftEditorLauncher::Form1::RegistryRead_VersionEditor(void)" (?RegistryRead_VersionEditor@Form1@WorldofWarcraftEditorLauncher@@$$FA$AAMP$AAVString@System@@XZ)	C:\programovani\WoW Editor\Test\src\Launcher\World of Warcraft - Editor Launcher.obj
Error	9	error LNK2019: unresolved external symbol "extern "C" long __stdcall RegOpenKeyExA(struct HKEY__ *,char const *,unsigned long,unsigned long,struct HKEY__ * *)" (?RegOpenKeyExA@@$$J220YGJPAUHKEY__@@PBDKKPAPAU1@@Z) referenced in function "private: class System::String ^ __clrcall WorldofWarcraftEditorLauncher::Form1::RegistryRead_VersionEditor(void)" (?RegistryRead_VersionEditor@Form1@WorldofWarcraftEditorLauncher@@$$FA$AAMP$AAVString@System@@XZ)	C:\programovani\WoW Editor\Test\src\Launcher\World of Warcraft - Editor Launcher.obj
Error	10	error LNK2019: unresolved external symbol "extern "C" long __stdcall RegSetValueExA(struct HKEY__ *,char const *,unsigned long,unsigned long,unsigned char const *,unsigned long)" (?RegSetValueExA@@$$J224YGJPAUHKEY__@@PBDKKPBEK@Z) referenced in function "private: void __clrcall WorldofWarcraftEditorLauncher::Form1::Updates_Registry(void)" (?Updates_Registry@Form1@WorldofWarcraftEditorLauncher@@$$FA$AAMXXZ)	C:\programovani\WoW Editor\Test\src\Launcher\World of Warcraft - Editor Launcher.obj
Aug 29, 2011 at 4:30pm
The MSDN entries for these functions -- RegCloseKey, RegOpenKeyEx, ... -- specifies the required header and lib file.

==> http://msdn.microsoft.com
Topic archived. No new replies allowed.