IceBrain Posted October 18, 2006 at 09:00 AM Report #58271 Posted October 18, 2006 at 09:00 AM Boas. Eu estou a fazer um "emulador do registo do windows", usando o programa WinAPIOverride32 que me permite 'redirigir' as chamadas às funções da API do windows (kernel32.dll, advapi32.dll, etc) para uma dll minha. Já tenho a função RegOpenKeyEx implementada mas tenho um problema com a função RegQueryValueEx: Tenho os dados a devolver num char*, mas não sei o como passá-lo para o lpData, até porque é uma LPBYTE. Quando chamo a função original, para passar um char* é só fazer (LPBYTE) var. Mas não consigo fazer o mesmo ao contrário... Função RegQueryValueEx http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/regqueryvalueex.asp Obrigado pela ajuda! ❝The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.❞- John Carmack on software patents A list of command line apps
shumy Posted October 18, 2006 at 09:10 AM Report #58272 Posted October 18, 2006 at 09:10 AM Não percebi muito bem o queres fazer! Algo do tipo "(char*) var" em que var é um LPBYTE? Aqui há coisa de 2 anos fazia umas malhas de croché, depois fartei-me e fui para informática!
IceBrain Posted October 18, 2006 at 10:53 AM Author Report #58287 Posted October 18, 2006 at 10:53 AM Eu criei uma função que emula a RegQueryValueEx. O código que tenho é: long mRegQueryValueExA(HKEY hKey, LPCTSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) { char resultado[50]; //Usando hKey, recolher os dados e inseri-los em resultado. //... //Se tudo correr bem, devolver os dados, alterando lpType, lpData e lpcbData if( strlen(res) > 1 ) { lpType = (LPDWORD) REG_SZ; lpData = (LPBYTE) res; lpcbData = sizeof(lpData); MessageBoxA(NULL, (char*) lpData, "So para verficar o valor de lpData", MB_OK); return 0; } Na message box, o valor está certo, mas depois quando a função retorna, lpData não está correcto. A função main() que chama RegQueryValueEx é: int main() { HKEY hkey; TCHAR lingua[50]; DWORD dwBufLen; RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Activision\\Call of Duty 2"), 0, KEY_QUERY_VALUE, &hkey); RegQueryValueEx(hkey, TEXT("Language"), NULL, NULL, (LPBYTE) lingua, &dwBufLen); MessageBoxA(NULL, lingua, "K::A", MB_OK); return 0; } Esta message box devolve um valor estranho. Qual será o problema? ❝The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.❞- John Carmack on software patents A list of command line apps
IceBrain Posted October 18, 2006 at 11:13 AM Author Report #58296 Posted October 18, 2006 at 11:13 AM Ok, já resolvi. em vez de lpData = (LPBYTE) res; fiz: memcpy(lpData, res, 50); ❝The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.❞- John Carmack on software patents A list of command line apps
shumy Posted October 18, 2006 at 12:07 PM Report #58307 Posted October 18, 2006 at 12:07 PM E percebeste qual é o problema? O tamanho da variavel vai ser sempre 50? No código não indicas onde definiste "res", que era a parte mais importante. Provavelmente se tiver um scope interno, o ponteiro não é válido quando sais da função. Parece-me ainda que seria possível usar directamente os parametros em vez de fazeres cópias, não? Aqui há coisa de 2 anos fazia umas malhas de croché, depois fartei-me e fui para informática!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now