添加项目文件。

This commit is contained in:
琴心
2022-04-26 15:31:46 +08:00
parent 4f1d4343fe
commit a1b66995e4
134 changed files with 18302 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
cmake_minimum_required ( VERSION 2.8...3.21 )
project (test_case5_exe)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set (srcs
main.cpp
)
set (hdrs
)
# libs
add_subdirectory (test_case5_dll)
include_directories ( test_case5_dll/include )
add_executable ( ${PROJECT_NAME} ${hdrs} ${srcs} )
target_link_libraries(${PROJECT_NAME} "test_case5_dll" )
#install
INSTALL( TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT ${PROJECT_NAME} )

View File

@@ -0,0 +1,16 @@
#include <Windows.h>
#include <iostream>
#include "api.h"
int main()
{
std::cout << "Test Case 5 started..." << std::endl;
DWORD checks = test_checksum1();
checks += test_checksum2();
checks += test_checksum3();
checks += test_checksum4();
checks += test_checksum5();
std::cout << "Test Case 5 finished, checks: " << std::hex << checks << std::endl;
return checks;
}

View File

@@ -0,0 +1,18 @@
cmake_minimum_required ( VERSION 2.8...3.21 )
project (test_case5_dll)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
include_directories ( include )
set (srcs
main.cpp
)
set (dll_hdrs
include/api.h
)
add_library ( ${PROJECT_NAME} SHARED ${dll_hdrs} ${srcs} main.def)
#install
INSTALL( TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT ${PROJECT_NAME} )

View File

@@ -0,0 +1,13 @@
#pragma once
#ifdef DLL_EXPORTS
#define DLL_API __declspec(dllexport) __stdcall
#else
#define DLL_API __declspec(dllimport) __stdcall
#endif
int DLL_API test_checksum1();
int DLL_API test_checksum2();
int DLL_API test_checksum3();
int DLL_API test_checksum4();
int DLL_API test_checksum5();

View File

@@ -0,0 +1,109 @@
#include <Windows.h>
#include <iostream>
#define DLL_EXPORTS
#include "api.h"
//#define SHOW_MSGBOX
inline DWORD rotl32a(DWORD x, DWORD n)
{
return (x << n) | (x >> (32 - n));
}
inline char to_lower(char c)
{
if (c >= 'A' && c <= 'Z') {
c = c - 'A' + 'a';
}
return c;
}
DWORD calc_checksum(BYTE *str, size_t buf_size, bool enable_tolower)
{
if (str == NULL) return 0;
DWORD checksum = 0;
for (size_t i = 0; i < buf_size; i++) {
checksum = rotl32a(checksum, 7);
char c = str[i];
if (enable_tolower) {
c = to_lower(c);
}
checksum ^= c;
}
return checksum;
}
int DLL_API test_checksum1()
{
char test1[] = "this is a test!";
DWORD checks = calc_checksum((BYTE*)test1, strlen(test1), true);
std::cout << "Checks 1: " << std::hex << checks << std::endl;
return checks;
}
int DLL_API test_checksum2()
{
wchar_t teststr[] = L"Checking wide strings";
DWORD checks = calc_checksum((BYTE*)teststr, sizeof(teststr), true);
#ifdef SHOW_MSGBOX
MessageBoxW(NULL, teststr, L"Test Case 5", MB_OK);
#endif
std::cout << "Checks 2: " << std::hex << checks << std::endl;
return checks;
}
int DLL_API test_checksum4()
{
wchar_t teststr[] = L"Test checksum 4";
DWORD checks = calc_checksum((BYTE*)teststr, sizeof(teststr), true);
#ifdef SHOW_MSGBOX
MessageBoxW(NULL, teststr, L"Test Case 5", MB_OK);
#endif
std::cout << "Checks 4: " << std::hex << checks << std::endl;
return checks;
}
int DLL_API test_checksum5()
{
wchar_t teststr[] = L"Yet another checksum test: 5";
DWORD checks = calc_checksum((BYTE*)teststr, sizeof(teststr), true);
#ifdef SHOW_MSGBOX
MessageBoxW(NULL, teststr, L"Test Case 5", MB_OK);
#endif
std::cout << "Checks 5: " << std::hex << checks << std::endl;
return checks;
}
int DLL_API test_checksum3()
{
SYSTEMTIME SystemTime;
GetSystemTime(&SystemTime);
TCHAR pszDate[200];
GetDateFormatA(LOCALE_USER_DEFAULT, DATE_LONGDATE, &SystemTime, NULL, pszDate, 200);
wchar_t teststr[] = L"Time func checksum";
DWORD checks = calc_checksum((BYTE*)teststr, sizeof(teststr), true);
std::cout << "Checks 3: " << std::hex << checks << std::endl;
#ifdef SHOW_MSGBOX
MessageBoxA(NULL, pszDate, "Test Case 5", MB_OK);
#endif
return checks;
}
BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
printf("Test Case 5 DLL loaded\n");
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

View File

@@ -0,0 +1,7 @@
LIBRARY test_case5_dll
EXPORTS
test_checksum1
test_checksum2 @2 NONAME
test_checksum3
test_checksum4 @4 NONAME
test_checksum5