brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 7734827 Raw
53 lines · cpp
1// UNSUPPORTED: target={{.*-windows-gnu}}2// XFAIL: msvc3 4// This is a host program for DLL tests.5//6// Just make sure we can compile this.7// The actual compile&run sequence is to be done by the DLL tests.8// RUN: %clang_cl_asan -Od %s -Fe%t9 10#include <stdio.h>11#include <windows.h>12 13int main(int argc, char **argv) {14  if (argc != 2) {15    printf("Usage: %s [client].dll\n", argv[0]);16    return 101;17  }18 19  const char *dll_name = argv[1];20 21  HMODULE h = LoadLibrary(dll_name);22  if (!h) {23    DWORD err = GetLastError();24    printf("Could not load DLL: %s (code: %lu)!\n", dll_name, err);25 26    LPSTR buf;27 28    FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |29                       FORMAT_MESSAGE_IGNORE_INSERTS,30                   NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 0,31                   NULL);32 33    printf("Error: %s\n", buf);34 35    LocalFree(buf);36 37    return 102;38  }39 40  typedef int (*test_function)();41  test_function gf = (test_function)GetProcAddress(h, "test_function");42  if (!gf) {43    printf("Could not locate test_function in the DLL!\n");44    FreeLibrary(h);45    return 103;46  }47 48  int ret = gf();49 50  FreeLibrary(h);51  return ret;52}53