CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Load DLL

  1. #1
    Join Date
    Jul 2004
    Posts
    1

    Question Load DLL

    I am hoping someone can help me .
    I want to use some functions from system DLL,"rsaenh.dll",
    but there are no exported functions from the DLL when main app performs a LoadLibrary on the DLL,(dynamic import),
    there are some codes I want to use the CPAcquirecontext() from rsaenh.dll)

    typedef BOOL (WINAPI * CPAcquireContext_DLL)(OUT HCRYPTPROV *phProv, IN LPCSTR szContainer, IN DWORD dwFlags , IN PVTableProvStruc pVTable);

    _declspec(dllimport) BOOL WINAPI CPAcquireContext(OUT HCRYPTPROV *phProv, IN LPCSTR szContainer, IN DWORD dwFlags, IN PVTableProvStruc pVTable);

    HINSTANCE hmod;
    hmod = ::LoadLibrary ("c:\\windows\\system32\\rsaenh.dll");
    if(hmod==NULL)
    {
    AfxMessageBox("Fail");
    }
    CPAcquireContext_DLL *lpproc;
    lpproc = (CPAcquireContext_DLL*)GetProcAddress (hmod,"CPAcquireContext");
    PVTableProvStruc pvTable=new VTableProvStruc;
    pvTable->Version=3;
    pvTable->FuncVerifyImage=(FARPROC ) (ProvVerifyImage);
    pvTable->FuncReturnhWnd=NULL;
    pvTable->dwProvType=PROV_RSA_FULL;
    pvTable->pbContextInfo=NULL;
    pvTable->cbContextInfo=0;

    if((*lpproc)(&hCryptProv, NULL, 0, pvTable))
    {
    printf("A cryptographic provider has been acquired. \n");
    }
    else
    {
    if((*lpproc)(&hCryptProv, NULL, CRYPT_NEWKEYSET, pvTable))
    {
    printf("A new key container has been created.\n");
    }
    else
    {
    HandleError("Could not create a new key container.\n");
    }

    }


    I find that it fails during the((*lpproc)(&hCryptProv, NULL, 0, pvTable)) call. It seems that it can not call the function.
    Is there something that I don't know about loading DLL?
    or can not load rsaenh.dll?
    Thanks for the advice

  2. #2
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384
    Quote Originally Posted by lfcgz
    I am hoping someone can help me .
    I want to use some functions from system DLL,"rsaenh.dll",
    but there are no exported functions from the DLL when main app performs a LoadLibrary on the DLL,(dynamic import),
    there are some codes I want to use the CPAcquirecontext() from rsaenh.dll)

    typedef BOOL (WINAPI * CPAcquireContext_DLL)(OUT HCRYPTPROV *phProv, IN LPCSTR szContainer, IN DWORD dwFlags , IN PVTableProvStruc pVTable);

    _declspec(dllimport) BOOL WINAPI CPAcquireContext(OUT HCRYPTPROV *phProv, IN LPCSTR szContainer, IN DWORD dwFlags, IN PVTableProvStruc pVTable);

    HINSTANCE hmod;
    hmod = ::LoadLibrary ("c:\\windows\\system32\\rsaenh.dll");
    if(hmod==NULL)
    {
    AfxMessageBox("Fail");
    }
    CPAcquireContext_DLL *lpproc;
    lpproc = (CPAcquireContext_DLL*)GetProcAddress (hmod,"CPAcquireContext");
    PVTableProvStruc pvTable=new VTableProvStruc;
    pvTable->Version=3;
    pvTable->FuncVerifyImage=(FARPROC ) (ProvVerifyImage);
    pvTable->FuncReturnhWnd=NULL;
    pvTable->dwProvType=PROV_RSA_FULL;
    pvTable->pbContextInfo=NULL;
    pvTable->cbContextInfo=0;

    if((*lpproc)(&hCryptProv, NULL, 0, pvTable))
    {
    printf("A cryptographic provider has been acquired. \n");
    }
    else
    {
    if((*lpproc)(&hCryptProv, NULL, CRYPT_NEWKEYSET, pvTable))
    {
    printf("A new key container has been created.\n");
    }
    else
    {
    HandleError("Could not create a new key container.\n");
    }

    }


    I find that it fails during the((*lpproc)(&hCryptProv, NULL, 0, pvTable)) call. It seems that it can not call the function.
    Is there something that I don't know about loading DLL?
    or can not load rsaenh.dll?
    Thanks for the advice
    First of all USE CODE TAGS plz.
    Secondly check if the return of GetProcAddress is NULL or something valid.
    Lastly call it like
    Code:
    if( !lpproc(&hCryptProv, NULL,  0, pvTable) )
    {
        // Error...
    }
    else
    {
        // Success...
    }
    Hope this helps,
    Regards,
    Usman.

  3. #3
    Join Date
    Feb 2002
    Posts
    3,788
    try the following and post the results.
    Code:
    	HINSTANCE hInstance = LoadLibrary("c:\\windows\\system32\\rsaenh.dll");
    	
    	if (!hInstance)
    		AfxMessageBox("The .dll library could not be loaded!");
    	
    	BOOL (*pFunction)(HCRYPTPROV *, CHAR *, DWORD, PVTableProvStruc);
    	
    	pFunction = (BOOL (*)(HCRYPTPROV *, CHAR *, DWORD, PVTableProvStruc)) GetProcAddress(hInstance, "CPAcquireContext");
    	
    	if (!pFunction)
    		AfxMessageBox("The function \"CPAcquireContext\" could not be found!");
    	
    	// call the function
    	//(*pFunction)(HCRYPTPROV *, CHAR *, DWORD, PVTableProvStruc);

  4. #4
    Join Date
    Feb 2004
    Posts
    232
    Bah, Alin beat it to me.
    Need help with anything related to audio programming? I can help!

  5. #5
    Join Date
    Feb 2002
    Posts
    3,788
    Quote Originally Posted by Ness
    Bah, Alin beat it to me.
    i did what ?

  6. #6
    Join Date
    Feb 2004
    Posts
    232
    Quote Originally Posted by Alin
    i did what ?

    I was about to post similar code, but you posted right before I did.
    Need help with anything related to audio programming? I can help!

  7. #7
    Join Date
    Feb 2002
    Posts
    3,788
    Quote Originally Posted by Ness
    I was about to post similar code, but you posted right before I did.
    i know what you meant, just teasing you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured