usedumpbin /exports dllsample2.dllto make sure the entrypoint is correct and then use some attrbutes like the following:   
[DllImport("Simple.Dll", EntryPoint="?TestCDECL_CPP@@YAXXZ", 
CallingConvention=CallingConvention.Cdecl )][DllImport("Simple.Dll", EntryPoint="?TestSTDCALL_CPP@@YGXXZ", 
CallingConvention=CallingConvention.StdCall)]

解决方案 »

  1.   

    试试在解决方案资源器的引用添加dll
      

  2.   

    我用你给的写了一个,调用没问题,有部分改动,如下所示:
    首先:
    DllSample.cpp's code
    #include "stdafx.h" 
    #include <stdio.h>
    int _declspec(dllexport) Add(int a,int b); 
    void _declspec(dllexport) ShowString(); int _declspec(dllexport) Add(int a,int b) 
    { return (a+b); } void _declspec(dllexport) ShowString() 

    printf("Nice to see you,I suceed!"); 

      

  3.   

    增加了一个DllSample.def
    EXPORTS
    Add
    ShowString
      

  4.   

    // stdafx.h : include file for standard system include files,
    //  or project specific include files that are used frequently, but
    //      are changed infrequently
    //#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
    #define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers#include <windows.h>
    // TODO: reference additional headers your program requires here//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
      

  5.   

    多谢思归大侠
    照你的方法 我试了一下
    结果如是:(我增加了一个函数Sub)F:\Microsoft Visual Studio\MyProjects\DllSample2\Debug>dumpbin /exports DllSample2.dll
    Microsoft (R) COFF/PE Dumper Version 7.00.9466
    Copyright (C) Microsoft Corporation.  All rights reserved.
    Dump of file DllSample2.dllFile Type: DLL  Section contains the following exports for DllSample2.dll    00000000 characteristics
        3E786950 time date stamp Wed Mar 19 20:57:52 2003
            0.00 version
               1 ordinal base
               4 number of functions
               4 number of names    ordinal hint RVA      name          1    0 00001019 ??4Easy@@QAEAAV0@ABV0@@Z
              2    1 0000100A ?Add@@YAHHH@Z
              3    2 00001014 ?ShowString@@YAXXZ
              4    3 0000100F ?Sub@@YAHHH@Z  Summary        4000 .data
            1000 .idata
            3000 .rdata
            2000 .reloc
           28000 .textI suppose that the functions and classes are properly exported
    but can you make some explanations to me,any thanks! 
      

  6.   

    C#的增加引入
    class DllSample
    {

    [DllImport("DllSample.DLL", EntryPoint="Add",  SetLastError=true,
    CharSet=CharSet.Ansi,
    CallingConvention=CallingConvention.StdCall)]
    public static extern int Add(int a,int b); [DllImport("DllSample.DLL", EntryPoint="ShowString",  SetLastError=true,
    CharSet=CharSet.Ansi,
    CallingConvention=CallingConvention.StdCall)]
    public static extern void ShowString();
    };调用如下没问题
    MessageBox.Show(DllSample.Add(1,2).ToString());
    DllSample.ShowString();
      

  7.   

    lgh3328(石头123) 兄弟,在解决方案资源器的引用添加dll我试过的
    但是提示:“未能添加对‘....dll’的引用。这不是有效的程序集或COM组件。只有具有.dll后缀名的程序或COM组件才能被引用。请确保该文件可访问,并是一个有效的程序集或COM组件”
    呵呵,
    gdi32.dll和wsnmp32等等也无法以这个办法添加,但是这样子用就可以:
    [DllImport("gdi32.dll")]
    static public extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);[DllImport("wsnmp32")] public static extern int SnmpCleanup();搞不懂为什么
      

  8.   

    还有一个伤脑筋的问题
    如果我的Dll中使用了自定义的结构,比如:
    typedef struct node
    {
     int serialNumber;
     char data[24];
     struct node* pNext;
    }Node,*pNode;而在导出函数中又以结构(或结构指针)为参数,例如:
    void Insert_Node(pNode current_node);
    那该怎么在.NET环境中使用呢?
      

  9.   

    其实C#调用Dll有时会很麻烦,主要是因为没有指针,而且类型最好是标准类型,否则更困难。我看你的程序,好像Dll和调用程序都是自己开发的,如果都选择同一种语言可能会好一些,要么避免传递非标准类型的数据。其实我用C#没多少时间,大家一起探讨吧!不过我上班的时候不能用QQ,还是用邮件联系吧,我的邮件地址 [email protected]
      

  10.   

    好的
    我的邮件地址:[email protected]
      

  11.   

    最近上Mop的
    猫崽一只