我有以下一段Dll代码,使用了一个WebBrowser控件,GetHandle为导出函数。
我在我的主程序里使用这个DLL的时候导致崩溃,请问各位前辈这是什么原因呢?
我应该如何做呢?我的目的是在dll中用一个webbrowser控件打开一个网站,然后
返回这个webbrowser控件的句柄,然后把这个控件设置成为主程序的子窗口。谢谢!
分数不多了,就还只有35分,我再开个号加一百分。unit Unit1;interfaceuses Unit2,SHDocVw;
var
  h:LongWord;
  b:TWebBrowser;
function GetHandle():LongWord;stdcall;
implementation
function GetHandle():LongWord;stdcall;begin
    b.Navigate('http://www.google.com');
    h:=b.Handle;
    Result:=h;
end;
initialization
finalization
end.

解决方案 »

  1.   

    你b都没创建立对象。
    你也使用Navigate,取Handle
    不崩溃才怪
      

  2.   

     b:TWebBrowser;
     
      b := TWebBrowser.create(nil);
      用完记得释放
       b.free;
      

  3.   

    unit Unit1;interfaceuses Unit2,SHDocVw;
    var
      h:LongWord;
      b:TWebBrowser;
    function GetHandle():LongWord;stdcall;
    implementation
    function GetHandle():LongWord;stdcall;
    begin
        b:=TWebBrowser.create(nil);
        b.Navigate('http://www.google.com');
        h:=b.Handle;
        Result:=h;
    end;
    initialization
    finalization
    end.
      

  4.   

    按照前辈的方法的确没问题了,谢谢!
    我在DLL工程写了如下代码,但我在主程序调用时写了如下代码:h:=GetHandle(Form1.Handle); webbrowser却没有显示在我主程序的form上,请问我当如何解决呢?谢谢!unit Unit1;interfaceuses Unit2,SHDocVw;
    var
      h:LongWord;
      b:TWebBrowser;
    function GetHandle(hwnd:LongWord):LongWord;stdcall;
    implementation
    function GetHandle(hwnd:LongWord):LongWord;stdcall;begin    b:=TWebBrowser.CreateParented(hwnd);
        b.Visible:=True;
        b.Height:=200;
        b.Width:=200;
        b.Top:=300;
        b.Left:=400;
        b.Navigate('http://www.google.com');
        Result:=h;
    end;
    initialization
    finalization
        b.Free;
    end.
      

  5.   

    谢谢!如下解决了:
        b:=TWebBrowser.Create(nil);
        b.Visible:=True;
        b.Height:=Height;
        b.Width:=Width;
        b.Top:=Top;
        b.Left:=Left;
        Windows.SetParent(b.Handle,hwnd);
        b.Navigate(URL);
        Result:=b.Handle;