各位大俠小弟用vc沒有几天﹐但是這次項目必須要用vc去寫。
主要是用vc寫個dll然后要到vb中調用。但是我從沒有用vc寫過dll。我現在只想快速入門。因為沒有太多的時間去翻資料找到寫dll的方法。
希望大俠們有空指點小弟一二。
class shipclass
{
private:
double dbnumbers ,dbweights,dbcubages;
public: string strtrackingnumber,strmaxicode,strzipcode;
shipclass shipmethod(){}
};
我想把這個類封裝到dll中
然后在vb中調用它。
能不能實現﹐如果能的話﹐該如何去封裝到dll中。操作方法越詳細越好。
我會高分回報。
小弟在線等﹐很急。

解决方案 »

  1.   

    建立一個dll工程,然後把有關的.h和.cpp文件加入進行,並在最上部加上你那個工程的頭文件,然後編譯輸出即可
      

  2.   

    現在我已經能夠在vb中調用用vc寫的簡單的函數了。
    我還不能解決如何調用如下的函數
    class csshipdata
    {
    public:
    string strtrackingnumber;
    string strmaxicode;
    string strzipcode;
    };
    csshipdata getshipinfo()
    {
    }
      

  3.   

    如果上面的很麻煩先幫我解決如下的問題﹐謝謝。
    我在test.cpp中定義
    extern "C" string APIENTRY csshipmethod(double numbers); 
    extern "C" string APIENTRY csshipmethod(double numbers)
    {
    return "ok";
    }
    編譯都不能通過。
      

  4.   

    可以这样
    class __declspec( dllexport ) csshipdata


    将整个类导出。
      

  5.   

    一建立一个MFC扩展DLL工程
    二按照下面的方法定义你的类
    class AFX_EXT_CLASS shipclass
    {
    private:
    double dbnumbers ,dbweights,dbcubages;
    public: string strtrackingnumber,strmaxicode,strzipcode;
    shipclass shipmethod(){}
    };
    三把需要引用的lib和h文件放到使用这个类的工程中,然后把编译生成的dll
    放到执行程序的同一个目录下就行了。
    不难,试试吧
      

  6.   

    謝謝codelover
    但現在還不想結貼。
    我在dll中定義了下面的函數
    LPSTR FAR PASCAL _export csshipmethod(double numbers)
    {
    return "ok";
    }
    在vb中我這樣調用
    Private Declare Function csshipmethod Lib "test.dll" (ByVal numbers As Double) As String
    Private Sub Command1_Click()
    Text1.Text = csshipmethod(12) 
    End Sub
    但text1沒有任何顯示。我想可能是LPSTR 類行在vb中不支持。可以幫忙幫我想一下嗎?
      

  7.   

    LPSTR 是一个 char* 类型;是字符串指针。