调用托管code从非托管c [英] Calling Managed Code From Unmanaged C

查看:164
本文介绍了调用托管code从非托管c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,大约一天半本后我做了零进展。

So after about a day and a half with this I've made zero progress.

我需要写在C DLL时使用的插件现有的应用程序。
该DLL已经由Visual Studio 2008的编译器有以下选项编译

I need to write a DLL in C that is used a plugin for an existing application. The DLL has to be compiled by the Visual Studio 2008 compiler with the following options

CL -DNT40 -DPOMDLL -DCRTAPI1 = _cdecl -DCRTAPI2 = CDECL -D_WIN32 -DWIN32 -DWIN32_LEA
  N_AND_MEAN -DWNT -DBYPASS_FLEX -D_INTEL = 1 -DIPLIB =无-I。 -IC:\\ PLM \\ 2T-RAC \\ TcEx
  press53 \\包括-IC:\\ Program Files文件(x86)的\\微软的Visual Studio 8 \\ VC \\包括
   -c -nologo -EHsc -W1 -Ox -Oy--MD C:\\ MYDIR \\ myDll.c

cl -DNT40 -DPOMDLL -DCRTAPI1=_cdecl -DCRTAPI2=cdecl -D_WIN32 -DWIN32 -DWIN32_LEA N_AND_MEAN -DWNT -DBYPASS_FLEX -D_INTEL=1 -DIPLIB=none -I. -I"C:\plm\2T-RAC\TcEx press53\include" -I"C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include" -c -nologo -EHsc -W1 -Ox -Oy- -MD C:\mydir\myDll.c

这是再联系到应用程序库的。

It's then linked to applications library's.

这实际需要做的,什么是造成我的问题是方法之一内,它需要从SQL Server 2008 R2中提取数据。

What it actually needs to do and what's causing me the issues is that within one of the methods it needs to pull data from a sql server 2008 r2.

从我今天看到你就不能直接在C ++做到这一点与SQL Server 2005以前的设计与CLR语言沟通(C#,C ++,VB.Net)。

From what I've seen today you wouldn't be able to do this directly in C as SQL Server past 2005 is designed to communicate with CLR languages( C#, C++, VB.Net).

有人建议我处理所有与VB.Net DLL数据库的通信,然后调用说,从C DLL中的功能。

It was suggested that I handle all the database communication with a VB.Net dll and then call said function from within the C dll.

大多数我所上调用托管的DLL从非托管code的的话题发现一直在谈论的PInvoke或COM包装和主要从C ++的角度。

Most of what I've found on the topic of calling managed dll's from unmanaged code has talked about pinvoke or com wrappers and mainly from the perspective of c++.

我有一个COM或任何提到的技术经验为零所以如果有人可以帮帮忙,这将是更AP preciated。

I have zero experience with COM or any mentioned techniques so if anyone could help out it would be much appreciated.

推荐答案

我解决了这个只不过是具有C DLL调用CMD,执行编译VB.NET的可执行文件和管道它的输出方式。
虽然这不是不是完全理想的解决方案是在这种情况下工作时,我都需要背一个字符串。

The way I resolved this was simply having the C dll call cmd and execute a compile VB.NET executable and pipe it's output. Although this isn't wasn't a totally ideal solution it worked in this situation when all I required back was a single string.

这篇关于调用托管code从非托管c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆