本帖最后由 darkfog 于 2009-08-04 10:18:05 编辑

解决方案 »

  1.   

    #include "newdll.h" 
    头文件里的函数是怎么定义的?
      

  2.   

    应用程序正常初始化(0xc0000005)失败。请单击“确定”,终止应用程序。
    ==============
    在隐式调用DLL时,应用程序一般是先加载DLL模块的,在加载DLL出错的情况下会出现应用程序正常初始化失败的错误,所以不应该是调用DLL中函数出了问题,而是加载的过程出错了。
      

  3.   

    的确是加载时出了问题
    按照书上说是
    “当所有的D L L模块都找到并且映射到进程的地址空间中之后,加载程序就会确定对输入的符号的全部引用。为此,它要再次查看每个模块的输入节。对于列出的每个符号,加载程序都要查看指定的D L L的输出节,以确定该符号是否存在。”
    当该符号不存在时将发生我出现的这个错误,问题是如何解决这个错误....
      

  4.   

    还是看一下你的DLL是不是成功导出相关的函数,很多DLL的问题都是出在这儿
      

  5.   

    头文件里是这样定义的
    #pragma   once
    #define DLLTESTAPI extern "C"__declspec(dllexport)
    DLLTESTAPI int add(int a,int b);
    cpp里面是这样的
    #include "newdll.h"
    int add(int a,int b)
    {
    return (a+b);

    }
      

  6.   

    对比一下调用成功的工程和失败的工程,runtime libarary等是否一致...
    自己检查一下lib是否正常正确
      

  7.   

    确认你的dll实现文件中声明的函数名及参数和导出的函数一致,调用时是否调用正确。
      

  8.   

    换成这样试试。#pragma  once
    #define DLLTESTAPI extern "C"__declspec(dllexport)
    DLLTESTAPI int WINAPI add(int a,int b);
    cpp里面是这样的
    #include "newdll.h"
    DLLTESTAPI int WINAPI add(int a,int b)
    {
    return (a+b);
    }
      

  9.   

    不行啊,这个
    1>e:\projects\newdll\newdll\newdll.h(8) : error C2146: syntax error : missing ';' before identifier 'add'
    1>e:\projects\newdll\newdll\newdll.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>.\newdll.cpp(7) : error C2146: syntax error : missing ';' before identifier 'add'
    1>.\newdll.cpp(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      

  10.   


    额,调用时是直接像这样调用的吧 int x=add(1,2);
    难道调用时有特殊的事情要做的?
      

  11.   

    头文件:
     #pragma   once
     #define DLLTESTAPI __declspec(dllexport)
     DLLTESTAPI int add(int a,int b);
     cpp里面是这样的
     #include "newdll.h"
     int __stdcall add(int a,int b)
     {
      return (a+b);
     }然后在调用dll的地方
    #pragma comment(lib,"newdll.lib")
    __declspec(dllimport) int add(int,int);
    再调用就行了。如果在生成导出库的时没加extern "C"话在导入时就不用加extern "C"了
      

  12.   

    所有代码
    newdll.h#pragma once
    #define DLLTESTAPI extern "C" __declspec(dllexport)
    DLLTESTAPI int  add(int a,int b);
    newdll.cpp#include "stdafx.h"
    #include "newdll.h"
    int add(int a,int b)
    {
    return a+b;
    }
    调用的CPP#include "stdafx.h"
    #include "newdll.h"
    #include "iostream"
    #pragma comment(lib,"newdll.lib")
    extern "C" __declspec(dllimport) int add(int,int); 
    using namespace std;int _tmain(int argc, _TCHAR* argv[])
    {
    int a;
    cout<<add(1,2)<<endl;
            cin>>a;
    return 0;
    }以上是照lostying的说法修改过的代码,调试仍然报相同的错
    另外,build时报  warning C4273: 'add' : inconsistent dll linkage
      

  13.   

    加了两个 __stdcall还是不行
      

  14.   

    工程属性中,call conversion把_cdecl改成__stdcall
      

  15.   

    那个add函数在调用的cpp和newdll.h中声明为了不同的类型,请LZ改成这样试试
    所有代码
    newdll.h#pragma once#if !defined(DLLTESTAPI)
    #define DLLTESTAPI extern "C" __declspec(dllimport)
    #endifDLLTESTAPI int  add(int a,int b);
    newdll.cpp#include "stdafx.h"
    #define DLLTESTAPI extern "C" __declspec(dllexport)
    #include "newdll.h"
    int add(int a,int b)
    {
    return a+b;
    }
    调用的CPP#include "stdafx.h"
    #include "newdll.h"
    #include "iostream"
    #pragma comment(lib,"newdll.lib")using namespace std;int WINAPI _tmain(int argc, _TCHAR* argv[])
    {
    int a;
    cout < <add(1,2) < <endl;
            cin>>a;
    return 0;
      

  16.   

    cpp改了? 报什么错误? LZ你这样不行啊。太搓了。不会至少得会问吧。都要让别人问你。
      

  17.   

    按 togoblime 的代码修改后出现
    无法定位程序输入点add于动态链接库 newdll.dll上
      

  18.   


    newdll.h 
    newdll.cpp 都改了
    报错跟原来一样
      

  19.   

    调用的cpp改了吗? 报什么错误? 全部贴上来。
      

  20.   

    】还是exe crash? 看重新编译的lib,dll等是否替换到了exe目录的
      

  21.   

    调用的CPP就长这样
    #include "stdafx.h"
    #include "newdll.h"
    #include "iostream"
    #pragma comment(lib,"newdll.lib")
    using namespace std;int _tmain(int argc, _TCHAR* argv[])
    {
    int a;
    cout<<add(1,2)<<endl;
        cin>>a;
    return 0;
    }跟最初的错误一样,毫无变化
      

  22.   

    把main中的add删掉。看是否依然报错。还有你main加WINAPI干嘛?
      

  23.   

    删掉也报错,
    cin和cout本来是想直接看看add的运行结果的-_- 。。
      

  24.   

    你是两边共用的头文件和lib还是copy过来的? 
      

  25.   

    然后刚才改了头文件。dll那边还没build。或者说了build了没copy过来?
      

  26.   

    没有,我每次都是改了之后rebuild一次再全部copy过来的
      

  27.   

    额,是不是我代码以外的地方有什么问题。哀,还是结了吧,自己有空了再研究研究,谢谢大家帮忙想办法, rendao0563 回的最勤奋,给你个大头吧