C++Builder 程序员博客
15 Dec
procedure a(s1: String); external 'ABC.dll'
procedure b(s1, s2: String); external 'ABC.dll'
procedure c; external 'ABC.dll'
procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
var
urlStr, headStr: String;
i, ipos: Integer;
IE: IWebbrowser2;
htmlDoc: IHTMLDocument2;
iColl: IHTMLElementCollection;
field: IHTMLElement;
iInputElement: IHTMLInputElement;
iSelectElement: IHTMLSelectElement;
begin
urlStr := URL;
i := 0;
Form1.Cursor := crHourGlass;
WebBrowser1.Cursor := crHourGlass;
ipos := Pos('_timewe_wapie_=',urlStr);
if ipos>0 then begin
headStr := Copy(urlStr,ipos+15,Length(urlStr)-ipos-14);
if strtofloatdef(headStr,0) <> strtofloatdef(headStr,1) then begin
i := 1;
headStr := Copy(urlStr,ipos+15,i);
while strtofloatdef(headStr,0) = strtofloatdef(headStr,1) do begin
Inc(i);
headStr := Copy(urlStr,ipos+15,i);
end;
headStr := Copy(urlStr,ipos+15,i-1);
end;
a(headStr);
i:=StrToInt(headStr);
IE := pDisp as IWebBrowser2;
if IE <> nil then begin
try
htmlDoc := IE.Document as IHTMLDocument2;
if htmlDoc <> nil then begin
iColl := htmlDoc.all.tags('INPUT') as IHTMLElementCollection;
if Assigned(IColl) then
for i := 0 to iColl.length-1 do
begin
field := iColl.item(i, 0) as IHTMLElement;
if Assigned(field) then
begin
iInputElement := iColl.item(i, 0) as IHTMLInputElement;
if Assigned(iInputElement) then
if iInputElement.type_ <> 'hidden' then begin
b(iInputElement.name, iInputElement.value);
end;
end;
end;
iColl := htmlDoc.all.tags('SELECT') as IHTMLElementCollection;
if Assigned(IColl) then
for i := 0 to iColl.length-1 do
begin
field := iColl.item(i, 0) as IHTMLElement;
if Assigned(field) then
begin
iSelectElement := field as IHTMLSelectElement;
if Assigned(iSelectElement) then begin
b(iSelectElement.name, iSelectElement.value);
end;
end;
end;
end;
except on E: Exception do
end;
end;
c;
end;
end;
没人会,不会吧?
太长了,其实都差不多
//前面是ABC这个dll里面3个导出函数的声明 void __declspec(dllimport) __stdcall a(String s1); void __declspec(dllimport) __stdcall b(String s1,String s2); void __declspec(dllimport) __stdcall c(void) ; // 下面的代码一样,写在BCB的CppWebBrowser1的那个OnBeforeNavigate2事件中 String urlStr , headStr ; int i,ipos; IWebBrowser2* IE ; IHTMLDocument2* htmlDoc; IHTMLElementCollection* iColl; IHTMLInputElement* iInputElement; IHTMLSelectElement* iSelectElement; urlStr = URL; i=0; Form1->Cursor = crHourGlass; WebBrowser1->Cursor = crHourGlass; ipos = urlStr.Pos("_timewe_wapie_="); if(ipos>0) { headStr =urlStr.SubString(ipos+15,urlStr.Length()-ipos-14); while(StrToFloatDef(headStr,0) != StrtoFloatDef(headStr,1)) { i =1 ; headStr = urlStr.SubString(ipos+15,i); } headStr = urlStr.SubString(ipos+15,i-1); } a( headStr); i =StrToInt(headStr); IE = dynamic_cast<IWebBrowser2*>(pDisp); if(IE) { try { htmlDoc=dynamic_cast<IHTMLDocument2*>(IE->Document); if(htmlDoc) { iColl = dynamic_cast<IHTMLElementCollection*>(htmlDoc->all->tags("INPUT")) ; if(iColl) { for( i = 0 ; i<=iColl->length-1 ; ++i) { field = dynamic_cast<IHTMLElement*>(iColl->item(i,0)) ; if(field) { iInputElement = dynamic_cast<IHTMLInputElement*>(iCol->item(i,0)); if(iInputElement) { if(iInputElement->type!=WideString("hidden")) { b(iInputElement->name,iInputElement->value); } } } } iColl = dynamic_cast<IHTMLElementCollection*>(htmlDoc->all->tags("SELECT")) ; if(iColl) { for( i = 0 ; i<=iColl->length-1 ; ++i) { field = dynamic_cast<IHTMLElement*>(iColl->item(i,0)) ; if(field) { iInputElement = dynamic_cast<IHTMLSelectElement*>(iCol->item(i,0)); if(iInputElement) { b(iInputElement->name,iInputElement->value); } } } } } } catch(Exception& e) { // ……….. } } c() ;
楼上很强
__stdcall >> pascal
哈哈
我正在把我的D转到C
帮你看下
就当俺啥也没说
人家都搞好了