示例#1
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE hLib;

    /* Initialize the PAL. */
    if ((PAL_Initialize(argc, argv)) != 0)
    {
        return (FAIL);
    }
    
    /*Load library (DLL). */
    hLib = LoadLibrary(LibraryName);

    if(hLib == NULL)
    {
        Fail("ERROR:%u:Unable to load library %s\n", 
             GetLastError(), 
             LibraryName);
    }

    /* Test access to DLL. */
    if(!TestDll(hLib, PASS))
        {
        Trace("ERROR: TestDll function returned FALSE "
             "expected TRUE\n.");
        FreeLibrary(hLib);
        Fail("");
    }

    /* Call the FreeLibrary API. */ 
    if (!FreeLibrary(hLib))
    {
        Fail("ERROR:%u: Unable to free library \"%s\"\n", 
             GetLastError(),
             LibraryName);
    }

    /* Test access to the free'd DLL. */
    if(!TestDll(hLib, FAIL))
    {
        Fail("ERROR: TestDll function returned FALSE "
            "expected TRUE\n.");
    }

    PAL_Terminate();
    return PASS;

}
示例#2
0
int main(void)
{
	TestDll();

	system("pause");
	return 0;
}
void CGroupHandler::FindDlls(void)
{
	std::vector<std::string> match;
	std::string dir("AI/Helper-libs");
	match = filesystem.FindFiles(dir, std::string("*.") + SharedLib::GetLibExtension());

	for (std::vector<std::string>::iterator it = match.begin(); it != match.end(); it++)
		TestDll(*it);
}
示例#4
0
文件: test1.c 项目: smartmaster/sscli
DWORD PALAPI CreateTestThread(LPVOID lpParam)
{
    /* Test access to DLL.*/
    TestDll(lpParam, 1);

    /*Free library and exit thread.*/
    FreeLibraryAndExitThread(lpParam, (DWORD)0);

    /* NOT REACHED */

    /*Infinite loop, we should not get here.*/
    while(1);

    return (DWORD)0;
}
void CGroupHandler::FindDlls(void)
{
	std::vector<std::string> match;
	std::string dir("aidll");
#ifdef _WIN32
	match = filesystem.FindFiles(dir,"*.dll");
#elif defined(__APPLE__)
	match = filesystem.FindFiles(dir,"*.dylib");
#else
	match = filesystem.FindFiles(dir,"*.so");
#endif
	for (std::vector<std::string>::iterator it = match.begin(); it != match.end(); it++) {
		TestDll(*it);
	}
}
示例#6
0
文件: test1.c 项目: smartmaster/sscli
BOOL  PALAPI StartThreadTest()
{
    HMODULE hLib;
    HANDLE  hThread;  
    DWORD   dwThreadId;
    LPTHREAD_START_ROUTINE lpStartAddress =  &CreateTestThread;
    LPVOID lpParameter = lpStartAddress;

    /*Load library (DLL).*/
    hLib = LoadLibrary(LibraryName);
    if(hLib == NULL)
    {
        Trace("ERROR: Unable to load library %s\n", LibraryName);
        
        return (FALSE);
    }

    /*Start the test thread*/
    hThread = CreateThread(NULL, 
                            (DWORD)0,
                            lpParameter,
                            hLib,
                            (DWORD)NULL,
                            &dwThreadId);
    if(hThread == NULL)
    {
        Trace("ERROR:%u: Unable to create thread.\n",
                GetLastError());

        FreeLibrary(hLib);
        return (FALSE);
    }

    /*Wait on thread.*/
    if(((WaitForSingleObject(hThread, 100)) != WAIT_OBJECT_0) &&
        ((WaitForSingleObject(hThread, 100)) != WAIT_TIMEOUT))
    {
        Trace("ERROR:%u: hThread=0x%4.4lx not exited by "
            "FreeLibraryAndExitThread\n",
            GetLastError(),  
            hThread);

        FreeLibrary(hLib);
        CloseHandle(hThread);
        return (FALSE);
    }
            
    /*Test access to DLL.*/
    if(!TestDll(hLib, 0))
    {
        Trace("ERROR: TestDll function returned FALSE "
            "expected TRUE\n.");
        
        FreeLibrary(hLib);
        CloseHandle(hThread);
        return (FALSE);
    }

    /*Clean-up thread.*/
    CloseHandle(hThread);

    return (TRUE);
}
示例#7
0
文件: test1.c 项目: 0-wiz-0/coreclr
BOOL  PALAPI StartThreadTest()
{
    HMODULE hLib;
    HANDLE  hThread;  
    DWORD   dwThreadId;
    LPTHREAD_START_ROUTINE lpStartAddress =  &CreateTestThread;
    LPVOID lpParameter = lpStartAddress;
    DWORD rc = -1;
    /*Load library (DLL).*/
    hLib = LoadLibrary(LibraryName);
    if(hLib == NULL)
    {
        Trace("ERROR: Unable to load library %s\n", LibraryName);
        
        return (FALSE);
    }

    /*Start the test thread*/
    hThread = CreateThread(NULL, 
                            (DWORD)0,
                            lpParameter,
                            hLib,
                            (DWORD)NULL,
                            &dwThreadId);
    if(hThread == NULL)
    {
        Trace("ERROR:%u: Unable to create thread.\n",
                GetLastError());

        FreeLibrary(hLib);
        return (FALSE);
    }

    /*Wait on thread.*/
    rc = WaitForSingleObject(hThread, TIMEOUT);
    if( rc != WAIT_OBJECT_0 )
    {
        Trace("ERROR:%u: hThread=0x%4.4lx not exited by "
            "FreeLibraryAndExitThread, RC[%d]\n",
            GetLastError(),  
            hThread, rc);

// There is a possibility that the other thread might 
// still be using the library VSW:337893
//        FreeLibrary(hLib);
        CloseHandle(hThread);
        return (FALSE);
    }
            
    /*Test access to DLL.*/
    if(!TestDll(hLib, 0))
    {
        Trace("ERROR: TestDll function returned FALSE "
            "expected TRUE\n.");
        
        CloseHandle(hThread);
        return (FALSE);
    }

    FreeLibrary(hLib);
    /*Clean-up thread.*/
    CloseHandle(hThread);

    return (TRUE);
}
示例#8
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE hFullLib;
    HANDLE hShortLib;
    HANDLE hRelLib;

    int    iRetVal  = FAIL;
    char   fullPath[_MAX_DIR];
    char drive[_MAX_DRIVE];
    char dir[_MAX_DIR];
    char relTestDir[_MAX_DIR];
    char fname[_MAX_FNAME];
    char ext[_MAX_EXT];
    
    BOOL bRc = FALSE;
    char   relLibPath[_MAX_DIR];


    /* Initialize the PAL. */
    if ((PAL_Initialize(argc, argv)) != 0)
    {
        return (FAIL);
    }

    /* Initalize the buffer.
     */
    memset(fullPath, 0, _MAX_DIR);

    /* Get the full path to the library (DLL).
     */
  
       if (NULL != _fullpath(fullPath,argv[0],_MAX_DIR)) {
	
	 _splitpath(fullPath,drive,dir,fname,ext);
	 _makepath(fullPath,drive,dir,LibraryName,"");
	 
	
	} else {
		Fail("ERROR: conversion from relative path \" %s \" to absolute path failed. _fullpath returned NULL\n",argv[0]);
	}

       /* Get relative path to the library
	*/
       _splitpath(argv[0], drive, relTestDir, fname, ext);
       _makepath(relLibPath,drive,relTestDir,LibraryName,"");


    /* Call Load library with the short name of
     * the dll.
     */
    hShortLib = LoadLibrary(LibraryName);
    if(hShortLib == NULL)
    {
        Fail("ERROR:%u:Short:Unable to load library %s\n", 
             GetLastError(), 
             LibraryName);
    }
    
    /* Test the loaded library.
     */
    if (!TestDll(hShortLib))
    {
        iRetVal = FAIL;
        goto cleanUpOne;
    }

    /* Call Load library with the full name of
     * the dll.
     */
    hFullLib = LoadLibrary(fullPath);
    if(hFullLib == NULL)
    {
        Trace("ERROR:%u:Full:Unable to load library %s\n", 
              GetLastError(), 
              fullPath);
        iRetVal = FAIL;
        goto cleanUpTwo;
    }

    /* Test the loaded library.
     */
    if (!TestDll(hFullLib))
    {
        iRetVal = FAIL;
        goto cleanUpTwo;
    }

    /*
    ** Call the load library with the relative path
    ** wrt to the directory ./testloadlibrary/.. 
    ** since we don't want to make any assumptions
    ** regarding the type of build
    */
    hRelLib = LoadLibrary(relLibPath);
    if(hRelLib == NULL)
    {
        Trace("ERROR:%u:Rel:Unable to load library at %s\n", 
              GetLastError(), relLibPath);
        iRetVal = FAIL;
        goto cleanUpTwo;
    }

    /* Test the loaded library.
     */
    if (!TestDll(hRelLib))
    {
        iRetVal = FAIL;
        goto cleanUpThree;
    }

   if( hRelLib != hFullLib )
   {
        Trace("Relative and Absolute Paths to libraries don't have same handle\n");
            iRetVal = FAIL;
            goto cleanUpThree;
   }

   if( hRelLib != hShortLib )
   {
        Trace("Relative and Short Paths to libraries don't have same handle\n");
            iRetVal = FAIL;
            goto cleanUpThree;
   }


   /* Test Succeeded.
     */
    iRetVal = PASS;

cleanUpThree:

    /* Call the FreeLibrary API. 
     */ 

    if (!FreeLibrary(hRelLib))
    {
        Trace("ERROR:%u: Unable to free library \"%s\"\n", 
              GetLastError(),
              relLibPath);
        iRetVal = FAIL;
    }

cleanUpTwo:

    /* Call the FreeLibrary API. 
     */ 
    if (!FreeLibrary(hFullLib))
    {
        Trace("ERROR:%u: Unable to free library \"%s\"\n", 
              GetLastError(),
              fullPath);
        iRetVal = FAIL;
    }

cleanUpOne:

    /* Call the FreeLibrary API. 
     */ 
    if (!FreeLibrary(hShortLib))
    {
        Trace("ERROR:%u: Unable to free library \"%s\"\n", 
              GetLastError(),
              LibraryName);
        iRetVal = FAIL;
    }


    /* Terminate the PAL.
     */
    PAL_Terminate();
    return iRetVal;

}
示例#9
0
//演示静态调用DLL
void CCallDLLByStaticDlg::OnBnClickedBtnCall()
{
	//TestDll函数为MyCEDLL.dll中的一个输出函数
	TestDll();
}