免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2432 | 回复: 3
打印 上一主题 下一主题

[函数] 请问一个windows下SDK函数用在msys下的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-06-15 16:04 |只看该作者 |倒序浏览
创建拨号连接的函数:RasCreatePhonebookEntry是windows下SDK函数,用来创建拨号连接(最下面有MSDN中此函数的介绍),此函数在ras.h中声明的,需要包含Rasapi32.lib库;
在vc环境下调用此函数只需要在visual studio中的 project/setting/link中加上此库、同时在调用此函数的文件中include “ras.h”就行了;
但是在msys中include “ras.h”、然后把Rasapi32.lib拷到程序开发目录、在makefile中添加对此lib的支持,但是在编译(make)时,总是提示找不到函数:
main.c:195: undefined reference to `RasCreatePhonebookEntryA@
请高手给指点,谢谢了!!!!
(顺便说一声,RasCreatePhonebookEntryA和RasCreatePhonebookEntry是一样的,在ras.h中define了,二者等同。)




==============
MSDN中RasCreatePhonebookEntry的介绍:
Remarks:
Windows 95/98/Me: RasCreatePhonebookEntryW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Requirements :
  Windows NT/2000/XP: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Ras.h.
  Library: Use Rasapi32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP. Also supported by Microsoft Layer for Unicode.

[ 本帖最后由 yalechen 于 2007-6-15 16:05 编辑 ]

论坛徽章:
24
狮子座
日期:2013-12-31 10:48:0015-16赛季CBA联赛之吉林
日期:2016-04-18 14:43:1015-16赛季CBA联赛之北控
日期:2016-05-18 15:01:4415-16赛季CBA联赛之上海
日期:2016-06-22 18:00:1315-16赛季CBA联赛之八一
日期:2016-06-25 11:02:2215-16赛季CBA联赛之佛山
日期:2016-08-17 22:48:2615-16赛季CBA联赛之福建
日期:2016-12-27 22:39:272016科比退役纪念章
日期:2017-02-08 23:49:4315-16赛季CBA联赛之八一
日期:2017-02-16 01:05:3415-16赛季CBA联赛之山东
日期:2017-02-22 15:34:5615-16赛季CBA联赛之上海
日期:2017-11-25 16:17:5015-16赛季CBA联赛之四川
日期:2016-01-17 18:38:37
2 [报告]
发表于 2007-06-17 12:23 |只看该作者

回复 1楼 yalechen 的帖子

原帖由 yalechen 于 2007-6-15 16:04 发表
创建拨号连接的函数:RasCreatePhonebookEntry是windows下SDK函数,用来创建拨号连接(最下面有MSDN中此函数的介绍),此函数在ras.h中声明的,需要包含Rasapi32.lib库;
在vc环境下调用此函数只需要在visual st ...


看看这个:

   http://www.mingw.org/mingwfaq.shtml#faq-msvcdll

How can an MSVC program call a MinGW DLL, and vice versa?

Assume we have a testdll.h, testdll.c, and testmain.c. In the first case, we will compile testdll.c with MinGW, and let the MSVC-compiled testmain call it. You should use
gcc -shared -o testdll.dll testdll.c \
    -Wl,--output-def,testdll.def,--out-implib,libtestdll.a

to produce the DLL and DEF files. MSVC cannot use the MinGW library, but since you have already the DEF file you may easily produce one by the Microsoft LIB tool: lib /machine:i386 /def:testdll.def

Once you have testdll.lib, it is trivial to produce the executable with MSVC:
cl testmain.c testdll.lib

Now for MinGW programs calling an MSVC DLL. We have two methods. One way is to specify the LIB files directly on the command line after the main program. For example, after
cl /LD testdll.c

use gcc -o testmain testmain.c testdll.lib

The other way is to produce the .a files for GCC. For __cdecl functions (in most cases), it is simple: you only need to apply the reimp tool from Anders Norlander (since his web site is no longer available, you may choose to download here a version enhanced by Jose Fonseca):
reimp testdll.lib
gcc -o testmain testmain.c -L. -ltestdll

However, for __stdcall functions, the above method does not work. For MSVC will prefix an underscore to __stdcall functions while MinGW will not. The right way is to produce the DEF file using the pexports tool included in the mingw-utils package and filter off the first underscore by sed:
pexports testdll.dll | sed "s/^_//" > testdll.def

Then, when using dlltool to produce the import library, add `-U' to the command line:
dlltool -U -d testdll.def -l libtestdll.a

And now, you can proceed in the usual way:
gcc -o testmain testmain.c -L. -ltestdll

Hooray, we got it.

论坛徽章:
0
3 [报告]
发表于 2007-06-18 10:16 |只看该作者

谢谢二楼!!!!!

谢谢二楼!!!!!
感激不尽

论坛徽章:
24
狮子座
日期:2013-12-31 10:48:0015-16赛季CBA联赛之吉林
日期:2016-04-18 14:43:1015-16赛季CBA联赛之北控
日期:2016-05-18 15:01:4415-16赛季CBA联赛之上海
日期:2016-06-22 18:00:1315-16赛季CBA联赛之八一
日期:2016-06-25 11:02:2215-16赛季CBA联赛之佛山
日期:2016-08-17 22:48:2615-16赛季CBA联赛之福建
日期:2016-12-27 22:39:272016科比退役纪念章
日期:2017-02-08 23:49:4315-16赛季CBA联赛之八一
日期:2017-02-16 01:05:3415-16赛季CBA联赛之山东
日期:2017-02-22 15:34:5615-16赛季CBA联赛之上海
日期:2017-11-25 16:17:5015-16赛季CBA联赛之四川
日期:2016-01-17 18:38:37
4 [报告]
发表于 2007-06-18 14:19 |只看该作者

回复 3楼 yalechen 的帖子

原帖由 yalechen 于 2007-6-18 10:16 发表
谢谢二楼!!!!!
感激不尽


MinGW / MSYS  的用户比较少,所以更应该互相帮助。    我现在主要用 MinGW / MSYS  配合 Linux 写一些源码可移植程序,其实用 MinGW / MSYS 写可移植程序并不轻松,win32 和 Linux 两个系统的差异太大了,有时不得不用条件编译等方法才行,Cygwin 更像 UNIX-like 环境,更容易使用,但是用 MinGW / MSYS 开发的程序运行速度比较快, MinGW / MSYS  的 License 也更加自由,可以用来开发商业软件。各位 MinGW / MSYS 和 dev-cpp 的用户,以后多交流吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP