Jak to nie działa? Załączyłeś windows.h?
Zakładam, że kolejność definicji struktur i wskaźnika jest dokładnie taka, jak podałem.
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
#pragma argsused
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <winbase.h>
#include <wingdi.h>
using namespace std;
struct genPid_t
{
DWORD cbSize;
WCHAR productId[48];
};
struct digPid_t
{
DWORD cbSize;
DWORD dwUnknown1;
CHAR productID[28];
CHAR editionID[16];
BYTE bUnknown2[112];
};
struct digPid4_t
{
DWORD cbSize;
DWORD unknown;
WCHAR extendedPID[64];
WCHAR activationID[72];
WCHAR editionID[304];
WCHAR subType[64];
WCHAR licenseType[49];
WCHAR licenseChannel[79];
};
typedef HRESULT (WINAPI *importFunction)(LPCWSTR,LPCWSTR,LPCWSTR,LPVOID,genPid_t*,digPid_t*,digPid4_t*);
int _tmain(int argc, _TCHAR* argv[])
{
WSTR Key = "";
importFunction GeneratePID;
int result;
// Load DLL file
HINSTANCE hinstLib = LoadLibrary(TEXT("pidgenx.dll"));
if (hinstLib == NULL) {
printf("ERROR: unable to load DLL\n");
return 1;
}
// Get function pointer
GeneratePID = (importFunction)GetProcAddress(hinstLib, "PidGenX");
if (GeneratePID == NULL) {
printf("ERROR: unable to find DLL function\n");
FreeLibrary(hinstLib);
return 1;
}
// Call function.
// Unload DLL file
FreeLibrary(hinstLib);
// Display result
return 0;
system("pause");
}
//---------------------------------------------------------------------------
(...) kompilator mówi że funkcja main jest źle zadeklarowana
- Kod: Zaznacz cały
return 0;
system("pause");
}
polymorphism napisał(a):A skąd tę funkcję main wytrzasnąłeś? Jeśli piszesz w BCB, to nie możesz ot tak dowolnie tworzyć funkcji main, bo od tego jest środowisko, które stworzy Ci odpowiednią wersję tej funkcji podczas tworzenia nowego projektu [...]
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
#pragma argsused
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <winbase.h>
#include <wingdi.h>
using namespace std;
struct genPid_t
{
DWORD cbSize;
WCHAR productId[48];
};
struct digPid_t
{
DWORD cbSize;
DWORD dwUnknown1;
CHAR productID[28];
CHAR editionID[16];
BYTE bUnknown2[112];
};
struct digPid4_t
{
DWORD cbSize;
DWORD unknown;
WCHAR extendedPID[64];
WCHAR activationID[72];
WCHAR editionID[304];
WCHAR subType[64];
WCHAR licenseType[49];
WCHAR licenseChannel[79];
};
typedef HRESULT (WINAPI *importFunction)(LPCWSTR,LPCWSTR,LPCWSTR,LPVOID,genPid_t*,digPid_t*,digPid4_t*);
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
String Key = "22TKD-F8XX6-YG69F-9M66D-PMJBM";
importFunction GeneratePID;
int result;
// Load DLL file
HINSTANCE hinstLib = LoadLibrary(TEXT("pidgenx.dll"));
if (hinstLib == NULL) {
printf("ERROR: unable to load DLL\n");
return 1;
}
// Get function pointer
GeneratePID = (importFunction)GetProcAddress(hinstLib, "PidGenX");
if (GeneratePID == NULL) {
printf("ERROR: unable to find DLL function\n");
FreeLibrary(hinstLib);
return 1;
}
// Call function.
GeneratePID(Key, "pkeyconfig.xrm-ms", "XXXX", 0, genPid_t*, digPid_t*, digPid4_t*);
// Unload DLL file
FreeLibrary(hinstLib);
// Display result
system("pause");
return 0;
}
//---------------------------------------------------------------------------
Co do tego return'a to i tak przerobię potem na aplikację GUI - piszę jako konsolową żeby tylko sprawdzić działanie
Mówi mi, że źle używam "genPid_t*" przywywołaniu funkcji
Problem rozwiazany: przed main'em trzeba było dodać "#pragma argsused".
Mówi mi, że źle używam "genPid_t*" przywywołaniu funkcji - to samo miałem przy kodzie, który jest w pierwszym poście
int _tmain(int argc, _TCHAR* argv[])
{
// definicje struktur:
genPid_t *structgP;
digPid_t *structdP;
digPid4_t *structdP4;
/* ... */
GeneratePID(Key.w_str(), L"pkeyconfig.xrm-ms", L"XXXX", 0, structgP, structdP, structdP4);
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <winbase.h>
#include <wingdi.h>
using namespace std;
struct genPid_t
{
unsigned int cbSize;
WCHAR productId[48];
};
struct digPid_t
{
unsigned int cbSize;
BYTE dwUnknown1[4];
CHAR productID[28];
CHAR editionID[16];
BYTE bUnknown2[112];
};
struct digPid4_t
{
unsigned int cbSize;
BYTE unknown[4];
WCHAR extendedPID[64];
WCHAR activationID[72];
WCHAR editionID[304];
WCHAR subType[64];
WCHAR licenseType[49];
WCHAR licenseChannel[79];
};
genPid_t *Base;
digPid_t *Adv;
digPid4_t *Pro;
typedef HRESULT (WINAPI *importFunction)(LPCWSTR,LPCWSTR,LPCWSTR,LPVOID,genPid_t*,digPid_t*,digPid4_t*);
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
genPid_t Base1;
digPid_t Adv1;
digPid4_t Pro1;
Base1.cbSize = 50;
Adv1.cbSize = 164;
Pro1.cbSize = 1272;
String Key = "22TKD-F8XX6-YG69F-9M66D-PMJBM";
importFunction GeneratePID;
// Load DLL file
HINSTANCE hinstLib = LoadLibrary(TEXT("pidgenx.dll"));
if (hinstLib == NULL) {
printf("ERROR: unable to load DLL\n");
system("pause");
}
// Get function pointer
GeneratePID = (importFunction)GetProcAddress(hinstLib, "PidGenX");
if (GeneratePID == NULL) {
printf("ERROR: unable to find DLL function\n");
FreeLibrary(hinstLib);
system("pause");
}
// Call function.
GeneratePID(Key.w_str(), L"pkeyconfig.xrm-ms", L"XXXX", 0, Base, Adv, Pro);
// Unload DLL file
FreeLibrary(hinstLib);
// Display result
char* i = Adv1.productID;
printf(i);
printf("\n");
system("pause");
}
//---------------------------------------------------------------------------
przeczytałem artykuł Barona o strukturach i już mniej więcej wiem o co kaman.
- Kod: Zaznacz cały
genPid_t *Base;
digPid_t *Adv;
digPid4_t *Pro;
(...)
genPid_t Base1;
digPid_t Adv1;
digPid4_t Pro1;
Base1.cbSize = 50; //<--- zobacz do czego służy sizeof()
Adv1.cbSize = 164; //<--- j/w.
Pro1.cbSize = 1272; //<--- j/w.
(...)
GeneratePID(Key.w_str(), L"pkeyconfig.xrm-ms", L"XXXX", 0, Base, Adv, Pro);
Chyba dam sobie spokój :/
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <winbase.h>
#include <wingdi.h>
using namespace std;
struct genPid_t
{
DWORD cbSize;
WCHAR productId[48];
};
struct digPid_t
{
DWORD cbSize;
BYTE dwUnknown1[4];
CHAR productID[28];
CHAR editionID[16];
BYTE bUnknown2[112];
};
struct digPid4_t
{
DWORD cbSize;
BYTE unknown[4];
WCHAR extendedPID[64];
WCHAR activationID[72];
WCHAR editionID[304];
WCHAR subType[64];
WCHAR licenseType[49];
WCHAR licenseChannel[79];
};
typedef HRESULT (WINAPI *importFunction)(LPCWSTR,LPCWSTR,LPCWSTR,LPVOID,genPid_t*,digPid_t*,digPid4_t*);
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
genPid_t Base;
digPid_t Adv;
digPid4_t Pro;
Base.cbSize = 50;
Adv.cbSize = 164;
Pro.cbSize = 1272;
String Key = "22TKD-F8XX6-YG69F-9M66D-PMJBM";
importFunction GeneratePID;
// Load DLL file
HINSTANCE hinstLib = LoadLibrary(TEXT("pidgenx.dll"));
if (hinstLib == NULL) {
printf("ERROR: unable to load DLL\n");
system("pause");
}
// Get function pointer
GeneratePID = (importFunction)GetProcAddress(hinstLib, "PidGenX");
if (GeneratePID == NULL) {
printf("ERROR: unable to find DLL function\n");
FreeLibrary(hinstLib);
system("pause");
}
// Call function.
GeneratePID(Key.w_str(), L"pkeyconfig.xrm-ms", L"XXXX", 0, &Base, &Adv, &Pro);
// Unload DLL file
FreeLibrary(hinstLib);
// Display result
char* i = Adv.editionID;
printf(i);
printf("\n");
system("pause");
}
//---------------------------------------------------------------------------
Wiem po co jest sizeof(), ale wartości wpisałem takie jakie mają być : 50, 164 i 1272
ona nie jest dla mnie akurat najwazniejsza, ale jak już wspominałem (może nie zwróciłeś uwagi), działa to tak, że wysyłam funkcji jako 3 ostatnie argumenty ciągi bajtów tak, by funkcja zmieniła ich wartości, i te wartości są kluczowe
a to Adv1.editionID generuje znaki:"└B*" gdzie gwiazdka to dowolny znak, zawsze inny o.0
Powrót do Ogólne problemy z programowaniem
Użytkownicy przeglądający ten dział: Brak zalogowanych użytkowników i 18 gości