# aardio 范例: 调用 GCC 之 C 语言



```aardio
//aardio 调用 GCC 之 C 语言
// gcc make 编译: https://www.aardio.com/zh-cn/docs/examples/Languages/GCC/makefile.html
// tcc 编译: https://www.aardio.com/zh-cn/docs/examples/Languages/C/dll.html

import process.gcc;

//创建 GCC 环境，参数指定 C/C++ 源码目录
var gcc = process.gcc("/");

//自动存为 main.c 
gcc.main = /*************
#include <windows.h>

int __stdcall DllMain(void * hinstDLL, unsigned long fdwReason, void * lpvReserved) {

	if (fdwReason == DLL_PROCESS_ATTACH){ 
		
	}
	return 1;
}

__declspec(dllexport) int TestW (const wchar_t* txt)  
{    
   	MessageBox(0,txt,u"GCC",0);
}
*************/

//生成 DLL。参数：-shared 生成 DLL，-s 移除调试符号减小体积， -municode 启用 Unicode
gcc.exec("main.c -o c.dll -shared -s -municode -m32 -O2 -static -lgcc -lstdc++")

//加载 DLL，默认使用 cdecl 调用约定
var dll = raw.loadDll("c.dll",,"cdecl");

/*
带 W 尾标的原生 API 传入 UTF-8 字符串时自动转换为  Unicode（UTF-16） 字符串
原生 API 尾标: https://www.aardio.com/zh-cn/docs/library-guide/builtin/raw/directCall.html
*/
dll.TestW("测试 UTF-8 自动转 Unicode（UTF-16） 字符串");
```

