我需要在c程序中调用一个vc程序中的函数
#include"CaptrueYUV.h"
#pragma comment(lib, "CaptrueYUV.lib")//dll中导出函数为vc函数
void main(int argc, char *argv[])
{
   int i3333;////////////////////////////////
   int Capture1();///////////////////////////////dll中的函数声明
   i3333 = Capture1();dll中的函数声明
}
错误:
main.obj : error LNK2001: unresolved external symbol _Capture1
Debug/tmn21.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.请指教是否这样调用?
错误原因?
vc中的这个函数为:
int Capture1(){
return 2;
  
}
急啊,请帮帮我!

解决方案 »

  1.   

    在vc中我是这样制作dll的。
    extern "C"{
    __declspec( dllexport ) int *Capture();
    }
      

  2.   

    void main(int argc, char *argv[])
    {
       int i3333;////////////////////////////////
       int Capture1();///////////////////////////////dll中的函数声明
       i3333 = Capture1();dll中的函数声明
    }这样应该不会通过编译吧
    函数内声明函数应该不行
      

  3.   

    根据你的制作过程
    #include"CaptrueYUV.h"
    #pragma comment(lib, "CaptrueYUV.lib")//dll中导出函数为vc函数
    void main(int argc, char *argv[])
    {
       int i3333;
       i3333 = Capture1();
    }
    这样应该没问题的
      

  4.   

    void main(int argc, char *argv[])
    {
       int i3333;////////////////////////////////
       int Capture1();///////////////////////////////dll中的函数声明
       i3333 = Capture1();dll中的函数声明
    }这样应该不会通过编译吧
    函数内声明函数应该不行
      
    //////////////////////////////
    要是没有int Capture1();///////////////////////////////这句错误如下:main.c
    H:\tmn21\main.c(98) : warning C4013: 'Capture1' undefined; assuming extern returning int
    Linking...
    main.obj : error LNK2001: unresolved external symbol _Capture1
    Debug/tmn21.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    也就是说我现在怀疑是dll中的这个函数没有导进来,可是我都是按照方法来做的阿,不知道为什么导不进来呢????这个问题困扰我好几天了,特郁闷
      

  5.   

    将考过来的头文件中的
    extern "C"{
    __declspec( dllexport ) int *Capture();
    }
    改为
    extern "C"{
    __declspec( dllimport ) int *Capture();
    }
      

  6.   

    编译dll时用
    extern "C"{
    __declspec( dllexport ) int *Capture();
    }
    编译其它dll或exe时用
    extern "C"{
    __declspec( dllimport ) int *Capture();
    }
      

  7.   

    按照你说的方法改了,现在的错误如下:
    main.c
    h:\tmn21\captrueyuv.h(3) : error C2059: syntax error : 'string'
    h:\tmn21\captrueyuv.h(14) : fatal error C1189: #error :  include 'stdafx.h' before including this file for PCH
    Error executing cl.exe.第一个错误箭头指向extern "C"{
      

  8.   

    mscf(扎西特勒) 
    按照你说的方法改了,现在的错误如下:
    main.c
    h:\tmn21\captrueyuv.h(3) : error C2059: syntax error : 'string'
    h:\tmn21\captrueyuv.h(14) : fatal error C1189: #error :  include 'stdafx.h' before including this file for PCH
    Error executing cl.exe.第一个错误箭头指向extern "C"{
      

  9.   

    你把#include "stdafx.h"加上去或设置环境不使用预编译头文件
      

  10.   

    stdafx.h也需要从那个工程里考过来吗???这个工程里没有
      

  11.   

    我快晕了,我把stdafx.h考了过来了,现在又有了这个错误
    c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(15) : fatal error C1189: #error :  MFC requires C++ compilation (use a .cpp suffix)
    Error executing cl.exe.
    是不是由于c程序不支持mfc的原因啊??
    我该怎么办?难道要把c程序都改成cpp???
      

  12.   

    你用c直接调用c++的dll可能就有这个问题,你写一个间接的文件看看!
      

  13.   

    就是在c++工程里加入一个c风格的文件,然后生成dll文件!