Salut à tous, dans le cadre d'un projet, j'aimerai utiliser la bibli CNG (cryptographi next generation) de Windows, mais voila quand je veux compiler l'exemple tout fait de windows pour voir un peu comment fonctionne les fonctions (LoL), ca ne compile pas
pour info tous les autres programme que j'ai pu faire eux compile parfaitement
je vous partage le code ainsi que mon message d'erreur, merci d'avance
#include <windows.h>
#include <stdio.h>
#include <bcrypt.h>
#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
#define STATUS_UNSUCCESSFUL ((NTSTATUS)0xC0000001L)
static const BYTE rgbMsg[] =
{
0x61, 0x62, 0x63
};
void __cdecl wmain(
int argc,
__in_ecount(argc) LPWSTR *wargv)
{
BCRYPT_ALG_HANDLE hAlg = NULL;
BCRYPT_HASH_HANDLE hHash = NULL;
NTSTATUS status = STATUS_UNSUCCESSFUL;
DWORD cbData = 0,
cbHash = 0,
cbHashObject = 0;
PBYTE pbHashObject = NULL;
PBYTE pbHash = NULL;
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(wargv);
//open an algorithm handle
if(!NT_SUCCESS(status = BCryptOpenAlgorithmProvider(
&hAlg,
BCRYPT_SHA256_ALGORITHM,
NULL,
0)))
{
wprintf(L"**** Error 0x%x returned by BCryptOpenAlgorithmProvider\n", status);
goto Cleanup;
}
//calculate the size of the buffer to hold the hash object
if(!NT_SUCCESS(status = BCryptGetProperty(
hAlg,
BCRYPT_OBJECT_LENGTH,
(PBYTE)&cbHashObject,
sizeof(DWORD),
&cbData,
0)))
{
wprintf(L"**** Error 0x%x returned by BCryptGetProperty\n", status);
goto Cleanup;
}
//allocate the hash object on the heap
pbHashObject = (PBYTE)HeapAlloc (GetProcessHeap (), 0, cbHashObject);
if(NULL == pbHashObject)
{
wprintf(L"**** memory allocation failed\n");
goto Cleanup;
}
//calculate the length of the hash
if(!NT_SUCCESS(status = BCryptGetProperty(
hAlg,
BCRYPT_HASH_LENGTH,
(PBYTE)&cbHash,
sizeof(DWORD),
&cbData,
0)))
{
wprintf(L"**** Error 0x%x returned by BCryptGetProperty\n", status);
goto Cleanup;
}
//allocate the hash buffer on the heap
pbHash = (PBYTE)HeapAlloc (GetProcessHeap (), 0, cbHash);
if(NULL == pbHash)
{
wprintf(L"**** memory allocation failed\n");
goto Cleanup;
}
//create a hash
if(!NT_SUCCESS(status = BCryptCreateHash(
hAlg,
&hHash,
pbHashObject,
cbHashObject,
NULL,
0,
0)))
{
wprintf(L"**** Error 0x%x returned by BCryptCreateHash\n", status);
goto Cleanup;
}
//hash some data
if(!NT_SUCCESS(status = BCryptHashData(
hHash,
(PBYTE)rgbMsg,
sizeof(rgbMsg),
0)))
{
wprintf(L"**** Error 0x%x returned by BCryptHashData\n", status);
goto Cleanup;
}
//close the hash
if(!NT_SUCCESS(status = BCryptFinishHash(
hHash,
pbHash,
cbHash,
0)))
{
wprintf(L"**** Error 0x%x returned by BCryptFinishHash\n", status);
goto Cleanup;
}
wprintf(L"Success!\n");
Cleanup:
if(hAlg)
{
BCryptCloseAlgorithmProvider(hAlg,0);
}
if (hHash)
{
BCryptDestroyHash(hHash);
}
if(pbHashObject)
{
HeapFree(GetProcessHeap(), 0, pbHashObject);
}
if(pbHash)
{
HeapFree(GetProcessHeap(), 0, pbHash);
}
}
RESULTAT CONSOLE
Scanning dependencies of target TESTAPIWINDOW
[ 50%] Building CXX object CMakeFiles/TESTAPIWINDOW.dir/main.cpp.obj
[100%] Linking CXX executable TESTAPIWINDOW.exe
c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\TESTAPIWINDOW.dir/objects.a(main.cpp.obj): in function `wmain':
C:/Users/DORO Enfguerrand/CLionProjects/TESTAPIWINDOW/main.cpp:36: undefined reference to `BCryptOpenAlgorithmProvider'
c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/DORO Enfguerrand/CLionProjects/TESTAPIWINDOW/main.cpp:47: undefined reference to `BCryptGetProperty'
c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/DORO Enfguerrand/CLionProjects/TESTAPIWINDOW/main.cpp:68: undefined reference to `BCryptGetProperty'
c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/DORO Enfguerrand/CLionProjects/TESTAPIWINDOW/main.cpp:89: undefined reference to `BCryptCreateHash'
c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/DORO Enfguerrand/CLionProjects/TESTAPIWINDOW/main.cpp:104: undefined reference to `BCryptHashData'
c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/DORO Enfguerrand/CLionProjects/TESTAPIWINDOW/main.cpp:115: undefined reference to `BCryptFinishHash'
c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/DORO Enfguerrand/CLionProjects/TESTAPIWINDOW/main.cpp:131: undefined reference to `BCryptCloseAlgorithmProvider'
c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/DORO Enfguerrand/CLionProjects/TESTAPIWINDOW/main.cpp:136: undefined reference to `BCryptDestroyHash'
c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/progra~2/mingw-w64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main':
C:\temp\gcc\build-mingw-w64\mingw-w64-crt/../../src/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\TESTAPIWINDOW.dir\build.make:85: TESTAPIWINDOW.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:72: CMakeFiles/TESTAPIWINDOW.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:84: CMakeFiles/TESTAPIWINDOW.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: TESTAPIWINDOW] Error 2
Il y a plein de "main" différents. On me corrigera si je dit des bêtises mais les plus utilisés :
main -> argv = char
wmain -> argv = wide char
WinMain -> Handle instance + argv = LPSTR
DllMain -> Par Load/Free Library
Et le point d'entrée attendu est défini dans "Project Properties >> Configuration Properties >> Linker >> System" sous SubSystem. Pour WinMain ce doit être Windows.
Comment vous avez fait gober ce truc à votre GCC ???
Normalement, avec les bons niveaux de warning, il devrait vous envoyer paitre.
Même sous MSVC, c'est tout pourri, sauf dans de très très rare cas (C-Runtime et consort).
Prenez l'habitude de spécifier les options du linker dans les options du linker et pas planquer dans un #pragma obscure dans un code source qui n'a pas grand-chose à voir avec la choucroute.
Je recherche un CDI/CDD/mission freelance comme Architecte Logiciel/ Expert Technique sur technologies Microsoft.
probleme de compilation
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
GZE, un moteur multiplateforme, adapté pour de la 2D, 3D et création de logiciels.