没人感兴趣吗?可以不断加分的具体情况是,访问数据库的所有函数都封装在C#写的一个DLL库里,我想通过VC.net调用这个动态库,访问数据库!好像和VC没什么关系,不过我以前一直在这里,知道这里高人多,版主不要删,谢谢了

解决方案 »

  1.   

    现在想尝试新的方法,因为采用的小组合作,负责数据库的选用了C#,我这边是用VC.net,所以....指导一下吧
      

  2.   

    不是说.net下所有语言可以相互调用吗?不会吧  ........
      

  3.   

    Is it possible to use C# DLL in C++ DLL or C++ Win32
    application ?
    You have to choices:
    1- You use the COM interop features of .NET to expose your C# classes as com
    objects, and use those from C++.
    2- Create a wrapper library in managed C++ and use that.Is it possible to call C# DLL (or managed C++ DLL ) in a 
    Win32 application in C++ (standard) ?I can't call a managed C++ DLL in a classic C++ DLL 
    because my managed C++ DLL contains some directives 
    unknown by C++ like : "use namespace System" or "__gc" ...
    Please, help meYou'll probably have to put the C# DLL in a COM callable 
    wrapper first which may require some work in exposing the 
    proper interface. You'll also have to use the tlbexp tool 
    to create a type library and the regasm tool to add a 
    reference to the DLL in the registry.
    Hope that helps get you started!我的观点是:managed C++ 能直接调用C#的dll吧?
      

  4.   

    A question: Is it possible to use PInvoke to use classes 
    stored in a VC++ DLL with C#? How? If you are talking about plain old C++ classes (not COM classes or
    managed classes) then no, it is not possible.  This doesn't mean that the
    DLL can't use classes internally, but if it was to pass a pointer out to
    .NET (through an IntPtr), then it would be worthless.If you have the .LIB and .H for this .DLL,
    you could write wrappers with the Managed Extension for VC++.If the question is:
    Can I create an instance of a unmanaged C++ class and call appropriate methods exposed by this class?The answer is you can't unless you are prepared for a change the C++ class.1. You need to specify CallingConvention.ThisCall in the DllimportAttribute.
    2. You need to specify the ordinal number as entry
    3. You need to add a class factory method to your C++ dll in order to create an instance of a C++ class
    4. You need to keep a list of outstanding references
    5 You need to explicitly destroy the owned instance from C#If you compare this to the creation of a managed wrapper, the latter is definitely the way to go.这些来自新闻组,希望对你有用。
    分数是小事情,如果成功了分享一下经验。
      

  5.   

    我觉得应该不存在“怎样访问”的问题——任何.NET Managed Language编译的结果都是Assembly,VC.NET编的C#编的Assembly没有太多的区别(这与传统的语言不同,没有参数类型的Marshal,没有Call Convention的限制...)。
    所以,VC.NET如何调用VC.NET的Assembly,就如何调用C#的Assembly,no difference:不外乎加reference引用而已——当然,Assembly必须在Local Direcotry正确部署,或者安装到GAC中。
    如果你用的是VC.NET的unmanaged属性,那就像CForce说的那样做——不过,现在写程序何必非要进到unmanaged部分呢?至少在Assembly的接口部分可以采用VC.NET的Managed代码,VC.NET是允许混合编程的,这样可维护性就好多了。
      

  6.   

     
     我用C#自定义的控键, 编译后是DLL,然后在VB.NET中调用的时候,只要 自定义工具箱——> .NET框架组件——>浏览 再加入哪个编译生成的DLL 就可以了 可惜我说的是自定义组件,不是DLL !:)