| www.delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:to:mime-version:subject:from:message-id:date | |
| :content-type; q=dns; s=default; b=b+ZFdeqBcxG46YD9uaxIHxeey9F9I | |
| HpwPzaRPXGjjRfXbdQK/H2JCtUKljMvt5cpL9YwxwAz9QkhnWN7nBA4wsC1uTt55 | |
| woaj+cWjgYfp72f4NPZjmZSY3gBSagnlhWyexq8+HNyvhwOTbRbLRTAyzZnZg/m4 | |
| vLTSbQyv+OzCWE= | |
| DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:to:mime-version:subject:from:message-id:date | |
| :content-type; s=default; bh=oUl6eRlzz2IILQ9ZINJ6kEArWi8=; b=NKP | |
| kXtKBIF8KBKmVus8TqAN3qnR+xKCa/c47Y4nZ4EfY69PpMLvBBKSkvUMmApj/1UD | |
| pNMkEF6QCX7utvFxMLGO2ixlwpsmWttq8zfCzlDXYttzHPJsQSzcseQZ+cPnjw7A | |
| 0jNxkIB5panU9MrmUivi5NaMB3p+RZmpRGJZj5SA= | |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| Authentication-Results: | sourceware.org; auth=none |
| X-Virus-Found: | No |
| X-Spam-SWARE-Status: | No, score=1.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 |
| X-HELO: | ni.com |
| To: | cygwin AT cygwin DOT com |
| MIME-Version: | 1.0 |
| Subject: | Question about having msvcrt*.dll and cygwin1.dll in one process |
| X-KeepSent: | A16137E6:A98D47F2-48257D93:002FE9C9; type=4; flags=0; name=$KeepSent |
| From: | Jing Zhao <jing DOT zhao AT ni DOT com> |
| Message-ID: | <OFA16137E6.A98D47F2-ON48257D93.002FE9C9-48257D93.00304419@ni.com> |
| Date: | Mon, 17 Nov 2014 16:47:11 +0800 |
| X-Proofpoint-Virus-Version: | vendor=fsecure engine=2.50.10432:5.13.68,1.0.28,0.0.0000 definitions=2014-11-17_01:2014-11-15,2014-11-16,1970-01-01 signatures=0 |
| X-IsSubscribed: | yes |
Hi all,
Cygwin FAQ 6.15 says that I cannot link with both MSVCRT*.dll and
cygwin1.dll since they are mutually exclusive. However, I can successfully
run a simple Windows console application which dynamically loads a dll
(compiled in Cygwin, thus linking to cygwin1.dll). The Windows console
application is built with Multi-threaded DLL (/MD). So what's the problem
of linking to both MSVCRT*.dll and cygwin1.dll. Am I missing anything?
// test.cpp, DLL code compiled in Cygwin
#include <stdio.h>
int hello(void)
{
printf ("welcome to linux world\n");
return 7777777;
}
This is the code to produce dll
$ gcc -g -O2 -c test.cpp
$ gcc -shared -o test.dll test.o
// main application compiled in MSVC, with /MD
#include <stdio.h>
#include <Windows.h>
int main()
{
char padding[32768];
memset(padding, 0, sizeof(padding));
HMODULE h = LoadLibrary(TEXT("C:\\cygwin64\\bin\\cygwin1.dll"));
if (!h)
{
DWORD code = GetLastError();
printf ("can't load cygwin1.dll, code %d\n", code);
return 0;
}
typedef void (WINAPI *INITFUC)();
INITFUC init = NULL;
init = (INITFUC) GetProcAddress(h, "cygwin_dll_init");
if (!init)
{
printf ("can't find cygwin_dll_init()\n");
return 0;
}
init();
h = LoadLibrary(TEXT("E:\\opensource\\Cygwin\\test\\test.dll"));
if (!h)
{
DWORD code = GetLastError();
printf ("can't load test.dll, code %d\n", code);
return 0;
}
typedef int (*MYFUNC)(void);
MYFUNC f = NULL;
f = (MYFUNC) GetProcAddress(h, "_Z5hellov");
if (!f)
{
printf ("can't find hello()\n");
return 0;
}
int res = (*f)();
printf ("res: %d\n", res);
printf ("it's over\n");
getchar();
return 0;
}
The outputs:
welcome to linux world
res: 7777777
it's over
So everything look fine. According to the FAQ 6.15, is there anything
that's potentially dangerous that I should be aware of, when linking both
msvcrt.dll and cygwin1.dll? Thanks a lot!
Thanks,
Jing Zhao @ Shanghai
Ext. 3273
8+ 7023273
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |