我有一个VB的程序需要调用一个DLL以实现某一简单图像处理功能。我因为C++不熟,就用C编了这么一个程序(主要是文件读入,输出及数组操作)。但现在需要在VC++的环境下将这个C程序,编译为DLL,请问需要做那些改动?另外,参数如何传递(DLL需要从VB得到两个整型变量参数,返回一个整型变量参数)?C的那段程序大体如下:#include <stdio.h>
#include <stdlib.h>
#include <math.h>void main()
{
FILE *raw_map,*out_map;
int y,x,j,i,m,n;  int gps_y,gps_x;
int long1_x,long2_x,lat1_y,lat2_y;
int long_x[9],lat_y[9];
int var_x,var_y;
int num_written; unsigned char pixels[450][450];
unsigned char domain[150][150];

// read-in campus.bmp is an image of 450x450 
raw_map = fopen("campus.raw","rb");  
for(y = 0; y < 450; y++)
             for(x = 0; x < 450; x++)
                 pixels[y][x] = fgetc(raw_map);
         fclose(raw_map);  long1_x = 5000, lat1_y = 2027;
long2_x = 5081, lat2_y = 2000; gps_x = 5030, gps_y = 2011; // These two var should be  
                                     // passed from VB program // coordinazied map area into ranges
var_x = (long2_x - long1_x)/9;
var_y = (lat1_y - lat2_y)/9; for (i=0;i<9;i++)
{
long_x[i] = long1_x + i*var_x;
lat_y[i] = lat1_y - i*var_y;
} // use gps data to locate the current range
m = 0, n = 0;
while (gps_x > long_x[m])
{
m = m + 1;
}
while (gps_y < lat_y[n])
{
n = n + 1;
} // m,n is the coordinates of current range         num_written = m + n;
         return num_written;
}这也不是程序的全部,大抵是这样,有些地方还需要修改,请大虾指教如何把这一C的程序转换成DLL?

解决方案 »

  1.   

    用_declspec(dllexport)声明一个函数就可以输出之
    用_declspec(dllimport)声明一个函数就可以输入之
    选择vc的新工程,选择win32 dll,按照所有的步骤选择一个输出简单函数的例子,
    之后看看援文件你就明白了
      

  2.   

    楼主的想法让我收获不少。
    我本来以为c不能写dll的。没有相关的库函数。因为dll是windows的概念。
    看来借着vc的帮助倒是可以。
      

  3.   

    用C在VC中编DLL是可以的,虽然有点土。只要在生命extern "C"...