Tag: interop

Ruby代码中的C / C ++?

C / C ++是编写Ruby应用程序的一些性能关键方面的好选择。 我知道这是可能的。 我想知道如何将C / C ++代码添加到Ruby代码中; 任何其他语言。 您是否在开源项目中注意到了这方面的实际应用?

Fortran接口调用返回指针的C函数

我有一个C函数, double* foofunc() { /* Function Body */ } 我不知道如何在Fortran声明一个接口来调用这个C函数。 此外,如果指针应该指向GPU device memory ,我怎么能在Fortran界面中定义它? 我是否需要使用DEVICE属性。 请使用Fortran支持的function,直到2003年。 有什么建议?

通过互操作接收字符串

我无法从我写的一些c代码中获取字符串。 首先是一些通常未分离的背景信息:我想从TAPI API接收TAPI TSP的用户可读字符串。 我已经实现了一个半可行的TAPI解决方案,依赖于匹配的驱动程序名称到存储的字符串,但是想要改变它以使用permanant line id,因为我们的一个客户有一个(阿尔卡特)PBX拒绝以任何其他方式工作。 在C中,我将头文件中的函数定义为: __declspec(dllexport) void GetDeviceName(long DeviceId, wchar_t* DeviceName); 这样写的function如下: __declspec(dllexport) void GetDeviceName(long DeviceId, wchar_t* DeviceName) { //tapi code here… //copy the string to DeviceName wcscpy(DeviceName, (wchar_t*)((char *)devCaps + devCaps->dwLineNameOffset)); } 如上所述,这最终会做一些有用的事情,但是现在我很高兴如果abc放在我的wchar_t * / StringBuilder中,我可以在C#中看到它。 在C#中我将函数定义为: [DllImport(“SBW.Tapi.TapiInterop.dll”, CharSet = CharSet.Auto)] static extern void GetDeviceName(long DeviceId, StringBuilder DeviceName); 我将DeviceName定义为StringBuilder,因为字符串是不可移植的,我希望DeviceName在C中设置( 这是MS推荐的 )。 […]

获取屏幕当前颜色filter的颜色

以下代码将屏幕的滤色器设置为特定颜色。 我怎样才能获得屏幕的颜色? [DllImport(“GDI32.dll”)] private unsafe static extern bool SetDeviceGammaRamp(IntPtr hdc, void* ramp); private static IntPtr hdc; public unsafe bool SetLCDbrightness(Color c) { short red = cR; short green = cG; short blue = cB; Graphics gg = Graphics.FromHwnd(IntPtr.Zero); hdc = gg.GetHdc(); short* gArray = stackalloc short[3 * 256]; short* idx = gArray; short brightness = […]

连接MinGW和MSVC之间的困境(未定义的引用)。 MinGW无法使用MSVC

我正在尝试移植最初使用MSVC完成的旧C .dll库,该库使用BEA Tuxedo库来使用MinGW。 我遇到过MSVC编译并链接一个文件但MinGW失败的情况。 实际问题在于连接阶段。 出现’未定义的引用’错误。 这是创建dll的最小示例:(tpsetunsol_test.c) #include void __stdcall msghandler(char *pszMessage, long lMessageLen, long lFlags) { } int Inittpsetunsol() { int ret = 0; tpsetunsol(msghandler); return ret; } 这编译没有错误: gcc -Wall -fexceptions -g -O2 -DWIN32 -DNDEBUG -D_WINDOWS -ID:/dev/tuxedo/include -o tpsetunsol_test.o -c tpsetunsol_test.c 出现错误: dllwrap –export-all-symbols -LD:/dev/tuxedo/lib -k –output-lib test.lib –output-def test.def –enable-stdcall-fixup –add-stdcall-alias -o […]

使用iso_c_binding在Fortran-C桥中的字符串数组

我正在编写将使用Fortran的C互操作性机制从Fortran调用C函数的代码(在Fortran 2003中引入并在较新版本的gfortran和ifort中实现)。 这个答案几乎就是我所需要的,但我不能完全了解我应该在Fortran中使用哪个接口声明来获得一个看起来像这样的C函数: int use_array(int n, char * array[]){ int i; for(i=0; i<n; i++){ printf("Item %d = %s\n",i,array[i]); } return n; } 我不清楚Fortran端的接口应该是什么声明: interface function use_array(n, x) bind(C) use iso_c_binding integer (c_int) use_array integer (c_int), value :: n character(c_char) WHAT_SHOULD_GO_HERE? :: x end function use_array end interface 我知道我也必须处理空终止问题。