diff --git a/MesApi/MesApi.sln b/MesApi/MesApi.sln new file mode 100644 index 0000000..3e372e3 --- /dev/null +++ b/MesApi/MesApi.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MesApi", "MesApi\MesApi.vcxproj", "{04F8460A-E9A1-43E4-B5CF-C1E30D24631D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test\Test.vcxproj", "{5CA99838-CB5D-4C18-8CD6-BCABAE89A2BD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {04F8460A-E9A1-43E4-B5CF-C1E30D24631D}.Debug|x64.ActiveCfg = Debug|x64 + {04F8460A-E9A1-43E4-B5CF-C1E30D24631D}.Debug|x64.Build.0 = Debug|x64 + {04F8460A-E9A1-43E4-B5CF-C1E30D24631D}.Debug|x86.ActiveCfg = Debug|Win32 + {04F8460A-E9A1-43E4-B5CF-C1E30D24631D}.Debug|x86.Build.0 = Debug|Win32 + {04F8460A-E9A1-43E4-B5CF-C1E30D24631D}.Release|x64.ActiveCfg = Release|x64 + {04F8460A-E9A1-43E4-B5CF-C1E30D24631D}.Release|x64.Build.0 = Release|x64 + {04F8460A-E9A1-43E4-B5CF-C1E30D24631D}.Release|x86.ActiveCfg = Release|Win32 + {04F8460A-E9A1-43E4-B5CF-C1E30D24631D}.Release|x86.Build.0 = Release|Win32 + {5CA99838-CB5D-4C18-8CD6-BCABAE89A2BD}.Debug|x64.ActiveCfg = Debug|x64 + {5CA99838-CB5D-4C18-8CD6-BCABAE89A2BD}.Debug|x64.Build.0 = Debug|x64 + {5CA99838-CB5D-4C18-8CD6-BCABAE89A2BD}.Debug|x86.ActiveCfg = Debug|Win32 + {5CA99838-CB5D-4C18-8CD6-BCABAE89A2BD}.Debug|x86.Build.0 = Debug|Win32 + {5CA99838-CB5D-4C18-8CD6-BCABAE89A2BD}.Release|x64.ActiveCfg = Release|x64 + {5CA99838-CB5D-4C18-8CD6-BCABAE89A2BD}.Release|x64.Build.0 = Release|x64 + {5CA99838-CB5D-4C18-8CD6-BCABAE89A2BD}.Release|x86.ActiveCfg = Release|Win32 + {5CA99838-CB5D-4C18-8CD6-BCABAE89A2BD}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {49D555BA-DD1B-4041-ACDE-4371CF88CAC5} + EndGlobalSection +EndGlobal diff --git a/MesApi/MesApi/MesApi.def b/MesApi/MesApi/MesApi.def new file mode 100644 index 0000000..f2ca97b --- /dev/null +++ b/MesApi/MesApi/MesApi.def @@ -0,0 +1,3 @@ +LIBRARY MesApi +EXPORTS + UploadResult @1 \ No newline at end of file diff --git a/MesApi/MesApi/MesApi.vcxproj b/MesApi/MesApi/MesApi.vcxproj new file mode 100644 index 0000000..671bd38 --- /dev/null +++ b/MesApi/MesApi/MesApi.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {04f8460a-e9a1-43e4-b5cf-c1e30d24631d} + MesApi + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + MESAPI_EXPORTS + true + NotUsing + pch.h + + + Windows + true + false + MesApi.def + winhttp.lib + + + + + Level3 + true + true + true + MESAPI_EXPORTS + true + NotUsing + pch.h + + + Windows + true + true + true + false + MesApi.def + winhttp.lib + + + + + Level3 + true + MESAPI_EXPORTS + true + NotUsing + pch.h + + + Windows + true + false + winhttp.lib + MesApi.def + + + + + Level3 + true + true + true + MESAPI_EXPORTS + true + NotUsing + pch.h + + + Windows + true + true + true + false + MesApi.def + winhttp.lib + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/MesApi/MesApi/MesApi.vcxproj.filters b/MesApi/MesApi/MesApi.vcxproj.filters new file mode 100644 index 0000000..6f42b46 --- /dev/null +++ b/MesApi/MesApi/MesApi.vcxproj.filters @@ -0,0 +1,44 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 头文件 + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件 + + + + + 源文件 + + + \ No newline at end of file diff --git a/MesApi/MesApi/dllmain.cpp b/MesApi/MesApi/dllmain.cpp new file mode 100644 index 0000000..daed8c8 --- /dev/null +++ b/MesApi/MesApi/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/MesApi/MesApi/framework.h b/MesApi/MesApi/framework.h new file mode 100644 index 0000000..80cbbc9 --- /dev/null +++ b/MesApi/MesApi/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/MesApi/MesApi/pch.cpp b/MesApi/MesApi/pch.cpp new file mode 100644 index 0000000..b6fb8f4 --- /dev/null +++ b/MesApi/MesApi/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: 与预编译标头对应的源文件 + +#include "pch.h" + +// 当使用预编译的头时,需要使用此源文件,编译才能成功。 diff --git a/MesApi/MesApi/pch.h b/MesApi/MesApi/pch.h new file mode 100644 index 0000000..9660927 --- /dev/null +++ b/MesApi/MesApi/pch.h @@ -0,0 +1,13 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +// 添加要在此处预编译的标头 +#include "framework.h" + +#endif //PCH_H diff --git a/MesApi/Test/Test.cpp b/MesApi/Test/Test.cpp new file mode 100644 index 0000000..998bbb7 --- /dev/null +++ b/MesApi/Test/Test.cpp @@ -0,0 +1,91 @@ +#include +#include +#include +#include + +// 定义 +typedef int(__stdcall* PFN_UploadResult)( + const char* sn, + const char* station, + const char* function, + const char* result, + const char* costtime, + char* outBuffer, + int bufferSize + ); + +// UTF-8 字符串转宽字符 +std::wstring ToWide(const char* utf8) +{ + if (!utf8 || !utf8[0]) return L""; + int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, nullptr, 0); + std::wstring wide(len - 1, L'\0'); + MultiByteToWideChar(CP_UTF8, 0, utf8, -1, &wide[0], len); + return wide; +} + +void TestDynamicLoad() +{ + std::wcout << L"===== 动态加载测试 =====" << std::endl; + + HMODULE hDll = LoadLibraryA("MesApi.dll"); + if (!hDll) + { + DWORD err = GetLastError(); + std::wcerr << L"加载 MesApi.dll 失败, 错误码: " << err << std::endl; + return; + } + std::wcout << L"[OK] DLL 加载成功" << std::endl; + + PFN_UploadResult pfnUpload = (PFN_UploadResult)GetProcAddress(hDll, "UploadResult"); + if (!pfnUpload) + { + std::wcerr << L"获取 UploadResult 函数地址失败" << std::endl; + FreeLibrary(hDll); + return; + } + std::wcout << L"[OK] 函数地址获取成功" << std::endl; + + char buffer[4096] = {}; + int ret = pfnUpload( + "SN20260402001", + "STA_STA_Touch", + "FC_TouchScreen", + "OK",//这里要写测试结果OK或者NG + "13.5", + buffer, + sizeof(buffer) + ); + + std::wcout << L"返回码: " << ret << std::endl; + std::wcout << L"返回值: " << ToWide(buffer) << std::endl; + + switch (ret) + { + case 0: std::wcout << L"[结果] 上传成功" << std::endl; break; + case -1: std::wcout << L"[结果] 网络错误" << std::endl; break; + case -2: std::wcout << L"[结果] MES 返回失败" << std::endl; break; + case -3: std::wcout << L"[结果] 缓冲区不足" << std::endl; break; + case -4: std::wcout << L"[结果] 未知异常" << std::endl; break; + default: std::wcout << L"[结果] 未定义返回码" << std::endl; break; + } + + FreeLibrary(hDll); + std::wcout << L"[OK] DLL 已释放\n" << std::endl; +} + +int main() +{ + _setmode(_fileno(stdout), _O_U16TEXT); + _setmode(_fileno(stderr), _O_U16TEXT); + + std::wcout << L"========================================" << std::endl; + std::wcout << L" MesApi DLL 接口测试 Demo" << std::endl; + std::wcout << L"========================================\n" << std::endl; + + TestDynamicLoad(); + + std::wcout << L"按回车键退出..." << std::endl; + std::wcin.get(); + return 0; +} \ No newline at end of file diff --git a/MesApi/Test/Test.vcxproj b/MesApi/Test/Test.vcxproj new file mode 100644 index 0000000..9a3c1ea --- /dev/null +++ b/MesApi/Test/Test.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {5ca99838-cb5d-4c18-8cd6-bcabae89a2bd} + Test + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/MesApi/Test/Test.vcxproj.filters b/MesApi/Test/Test.vcxproj.filters new file mode 100644 index 0000000..a034dfc --- /dev/null +++ b/MesApi/Test/Test.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file