線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:8108
推到 Plurk!
推到 Facebook!

如何執行 *.udl 並等待 ??

尚未結案
pahan
一般會員


發表:1
回覆:7
積分:1
註冊:2002-09-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-09-16 12:19:47 IP:210.243.xxx.xxx 未訂閱
各位大大: 因為我要在程式中讓使用者自行設定TADOConnection的連線字串 所以我需要執行ConnectionSQL.udl 我先是使用下列方法: ShellExecute(NULL,"open","ConnectionSQL.udl",NULL,NULL,SW_SHOW); 但是因為ShellExecute並不能傳回HANDLE, 所以我就不能使用WaitForSingleObject來讓程式等待 後來我改用CreatProcess: TStartupInfo StartupInfo; TProcessInformation ProcessInformation; StartupInfo.cb=sizeof(TStartupInfo); StartupInfo.dwFlags=STARTF_USESHOWWINDOW; StartupInfo.wShowWindow=SW_NORMAL; if(CreateProcess(NULL, "ConnectionSQL.udl",NULL, NULL, true, NORMAL_PRIORITY_CLASS, NULL, NULL,&StartupInfo, &ProcessInformation)) WaitForSingleObject(ProcessInformation.hProcess, INFINITE); 但是沒辦法執行,我去看檔案類型連結 udl的資訊如下: Microsoft 資料連結 (Rundll32.exe C:\PROGRA~1\COMMON~1\SYSTEM\OLEDB~1\OLEDB32.DLL,OpenDSLFile %1) 也就是說要啟動UDL還必須要執行dll檔,請問我應該要如何設定才可以,請大家幫幫忙,謝謝。
lcsboy
版主


發表:87
回覆:622
積分:394
註冊:2002-06-18

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-09-16 14:49:55 IP:211.23.xxx.xxx 未訂閱
更正: ShellExecute可以傳回Handle 而且我實作過了, 請參考 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=19897
pahan
一般會員


發表:1
回覆:7
積分:1
註冊:2002-09-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-09-16 19:20:23 IP:210.243.xxx.xxx 未訂閱
我的source code 如下:  
DWORD INFINTE=0xFFFF;
HANDLE hnd;    hnd=ShellExecute(NULL,"open","d:\ConnectionSQL.udl",NULL,NULL,SW_SHOW);    WaitForSingleObject(hnd,INFINTE);
ShowMessage("hi");
 
這樣子執行的話依然會跑出”hi”,我看了一下msdn,裡面是說 ShellExecute的return value 是屬於HINSTANCE,內容如下: If the function succeeds, the return value is the instance handle of the application that was run, or the handle of a dynamic data exchange (DDE) server application. If the function fails, the return value is an error value that is less than or equal to 32. The following table lists these error values 我還是試不出來說,請大大再次幫忙謝謝!!
lcsboy
版主


發表:87
回覆:622
積分:394
註冊:2002-06-18

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-09-16 20:49:20 IP:210.85.xxx.xxx 未訂閱
這位同學: hnd=ShellExecute(NULL,"open","d:\ConnectionSQL.udl",NULL,NULL,SW_SHOW); 改成 hnd=ShellExecute(NULL,"open","d:\\ConnectionSQL.udl",NULL,NULL,SW_SHOW); 看出那裡不同了嗎?
pahan
一般會員


發表:1
回覆:7
積分:1
註冊:2002-09-16

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-09-17 08:24:40 IP:210.243.xxx.xxx 未訂閱
lcsboy大大: 還是依樣耶,我就算是拿EXE的執行檔也是不行。 我用的是bcb6和win98,不管怎樣謝謝你了, 我會在試試看。
pahan
一般會員


發表:1
回覆:7
積分:1
註冊:2002-09-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2002-09-17 08:24:43 IP:210.243.xxx.xxx 未訂閱
lcsboy大大: 還是依樣耶,我就算是拿EXE的執行檔也是不行。 我用的是bcb6和win98,不管怎樣謝謝你了, 我會在試試看。
jieshu
版主


發表:42
回覆:894
積分:745
註冊:2002-04-15

發送簡訊給我
#7 引用回覆 回覆 發表時間:2002-09-17 09:32:02 IP:203.204.xxx.xxx 未訂閱
引言: 各位大大: 因為我要在程式中讓使用者自行設定TADOConnection的連線字串
不知BCB是否有PromptDataSource這個Function直接就可叫出Connection的設定畫面,記得要uses ADODB。 然後再自行存成文字檔即可。
人生有夢,逐夢而行。 人若為善,福雖未至,禍已遠離。 人若為惡,禍雖未至,福已遠離。 http://www.taconet.com.tw/jieshu/
------
人生有夢,逐夢而行
人若為善,福雖未至,禍已遠離
人若為惡,禍雖未至,福已遠離
http://www.taconet.com.tw/jieshu/
ericosur
一般會員


發表:0
回覆:15
積分:8
註冊:2002-08-08

發送簡訊給我
#8 引用回覆 回覆 發表時間:2002-09-17 12:50:55 IP:61.13.xxx.xxx 未訂閱
回應一下pahan先生/小姐的文章: 你說到 ShellExecute() 會傳回 HINSTANCE 可是我看 msdn library 裡面提到傳回值: Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. The only thing that can be done with the returned HINSTANCE is to cast it to an int and compare it with the value 32 or one of the error codes below    簡單翻譯一下,傳回值為了與16位元應用程式相容才傳回HINSTANCE, 現在只能轉型別為 int 作為錯誤值檢查,而不是真的 HINSTANCE 值。    如果要取得 process handle 的話,要用新版本 ShellExecuteEx(), 不過呼叫方式複雜多了,順便看一下 ShellExecuteEx() 的傳回值變成 BOOL    // 您的 msdn 是哪一版的?不大一樣,小弟查了一下 web 版和手頭的 July 版 // 是一樣的,用太舊的 msdn 很危險的...
pahan
一般會員


發表:1
回覆:7
積分:1
註冊:2002-09-16

發送簡訊給我
#9 引用回覆 回覆 發表時間:2002-09-18 18:21:04 IP:210.243.xxx.xxx 未訂閱
Dear all : 我去看了一下MSDN,ShellExecuteEx好像是nt的東西,我的到真的是舊舊的資料 至於jieshu 大大提的方案就更是看不懂了,參數太多了,不知該怎麼下手....@@
jieshu
版主


發表:42
回覆:894
積分:745
註冊:2002-04-15

發送簡訊給我
#10 引用回覆 回覆 發表時間:2002-09-20 16:10:02 IP:203.204.xxx.xxx 未訂閱
引言: Dear all : 我去看了一下MSDN,ShellExecuteEx好像是nt的東西,我的到真的是舊舊的資料 至於jieshu 大大提的方案就更是看不懂了,參數太多了,不知該怎麼下手....@@
不會吧!在Delphi下PromptDataSource只要如下即可執行 PromptDataSource(Handle, ADOConnection1.ConnectionString); 怎麼BCB的會有很多參數很複雜嗎?
人生有夢,逐夢而行。 人若為善,福雖未至,禍已遠離。 人若為惡,禍雖未至,福已遠離。 http://www.taconet.com.tw/jieshu/
------
人生有夢,逐夢而行
人若為善,福雖未至,禍已遠離
人若為惡,禍雖未至,福已遠離
http://www.taconet.com.tw/jieshu/
pahan
一般會員


發表:1
回覆:7
積分:1
註冊:2002-09-16

發送簡訊給我
#11 引用回覆 回覆 發表時間:2002-09-20 17:39:54 IP:210.243.xxx.xxx 未訂閱
小弟找的資料長這樣:  
IDBPromptInitialize::PromptDataSource
Opens the Data Link Properties dialog box. Returns a connection string.    HRESULT PromptDataSource(       IUnknown *          pUnkOuter
   HWND                hWndParent,
   DBPROMPTOPTIONS     dwPromptOptions,
   ULONG               cSourceTypeFilter,
   DBSOURCETYPE *      rgSourceTypeFilter,
   LPCOLESTR           pwszszzProviderFilter,
   REFIID              riid,
   IUnknown **         ppDataSource);
Parameters    pUnkOuter [in]    A pointer to the controlling IUnknown interface if the data source object is being created as a part of an aggregate; otherwise, it is a null pointer.    hWndParent [in]    The parent window handle for dialog boxes to be displayed. The dialog box will always be centered within this window.    dwPromptOptions [in]    Specifies whether to prompt with the Create New Data Link wizard or the Data Link Properties dialog box.    Value Meaning 
DBPROMPTOPTIONS_WIZARDSHEET Prompt with Create New Data Link wizard. 
DBPROMPTOPTIONS_PROPERTYSHEET Prompt with Data Link Properties dialog box.     cSourceTypeFilter [in]    Count of elements in rgSourceTypeFilter. The only valid value is zero.    This is reserved for future use.    rgSourceTypeFilter [in]    This parameter is ignored unless cSourceTypeFilter is greater than zero. Otherwise, this parameter points to a valid array of DBSOURCETYPE values. If it is non-null, the providers presented to the user will be limited to those that match the SOURCE_TYPEs specified in rgSourceTypeFilter.    This is reserved for future use.    pwszszzProviderFilter [in]    A double null-terminated string of ProgIDs.    This parameter must be null, or point to a valid string. If it is non-null, the providers presented to the user will be limited to those that match the providers' ProgIDs specified in pwszszzProviderFilter. If only one provider is specified, and DBPROMPTOPTIONS_WIZARDSHEET is specified, the provider selection page is not displayed.    riid [in]    The requested interface for the data link returned in *ppDataSource.    ppDatasource [in, out]    A pointer to a data source object (DSO).    If *ppDataSource is null on entry, then Prompt generates a new DSO based on the information specified by the user, and returns a pointer to that DSO in *ppDataSource.    If *ppDataSource is non-null on entry, Prompt uses the properties returned by IProperties::GetProperties() as initial values. If the user selects a different provider, Prompt will release the original *ppDataSource and create a new data source. On exit, *ppDataSource will be set to a pointer to the interface specified by riid.     Return Code    S_OK    The method succeeded.    E_FAIL    A provider-specific error occurred.    DB_E_CANCELED    The user canceled the dialog.    E_NOINTERFACE    The data source did not support the interface specified in riid.    riid was IID_NULL.    *ppDatasource was not null and did not indicate an OLE DB data source generated from IDataInitialize or IDBPromptInitialize.    DB_E_NOAGGREGATION    pUnkOuter was not a null pointer and riid was something other than IID_IUnknown.    pUnkOuter was not a null pointer and the provider does not support aggregation.    E_INVALIDARG    ppDatasource was a null pointer.    cSourceTypeFilter was not zero and rgSourceTypeFilter was a null pointer.    An element in rgSourceTypeFilter was not a valid filter.    dwPromptOptions was an invalid value.    Comments    None.    Code Example    The following code fragment shows how a consumer might use IDBPromptInitialize::PromptDataSource to prompt the user for connection information:    // First CoCreate the OLE DB Service Component Manager
//    HRESULT               hr                    =S_OK;
IDataInitialize      *pIDataInitialize      =NULL;    hr = CoCreateInstance(
         CLSID_DataLinks, 
         NULL, 
         CLSCTX_INPROC_SERVER, 
         IID_IDataInitialize, 
         reinterpret_cast(pIDataInitialize));    // CreateDBInstance to instantiate previously stored provider
//    CLSID               clsidProvider     (GetProviderCLSID());
IDBProperties       *pIDBProperties   =NULL;    hr = pIDataInitialize->CreateDBInstance(
          clsidProvider,
          NULL,
          CLSCTX_INPROC_SERVER,
          NULL,
          IID_IDBProperties,
          reinterpret_cast(&pIDBProperties));    // Set some previously stored properties
//    ULONG             cPropertySets           (GetPropertySetsCount());
DBPROPSET         (*rgPropertySets)        (GetPropertySets());    hr = pIDBProperties->SetProperties(cPropertySets, rgPropertySets);    // Prompt the user to view/edit the connection information
//    IDBPromptInitialize   *pIDBPromptInitialize   =NULL;    hr = pIDataInitialize ->QueryInterface(
         IID_IDBPromptInitialize, 
         reinterpret_cast(&pIDBPromptInitialize));    hr = pIDBPromptInitialize->PromptDataSource(
         NULL,
         hWndParent,
         DBPROMPTOPTIONS_WIZARD,
         0, NULL, 
         NULL,
         IID_IDBProperties,
         &pIDBProperties);     
這是我從我舊舊的MSDN剪下來的,也許是我找錯了吧.. 不過在bcb上我不太會查資料說,有時候不一定知道全名 還有大大的用法我直接剪下貼上不能執行,我又找不到說明 可不可以再幫幫忙,謝謝!!
jieshu
版主


發表:42
回覆:894
積分:745
註冊:2002-04-15

發送簡訊給我
#12 引用回覆 回覆 發表時間:2002-09-23 11:57:17 IP:203.204.xxx.xxx 未訂閱
引言: 小弟找的資料長這樣:
IDBPromptInitialize::PromptDataSource
Opens the Data Link Properties dialog box. Returns a connection string.    HRESULT PromptDataSource(       IUnknown *          pUnkOuter
   HWND                hWndParent,
   DBPROMPTOPTIONS     dwPromptOptions,
   ULONG               cSourceTypeFilter,
   DBSOURCETYPE *      rgSourceTypeFilter,
   LPCOLESTR           pwszszzProviderFilter,
   REFIID              riid,
   IUnknown **         ppDataSource);
Parameters    pUnkOuter [in]    A pointer to the controlling IUnknown interface if the data source object is being created as a part of an aggregate; otherwise, it is a null pointer.    hWndParent [in]    The parent window handle for dialog boxes to be displayed. The dialog box will always be centered within this window.    dwPromptOptions [in]    Specifies whether to prompt with the Create New Data Link wizard or the Data Link Properties dialog box.    Value Meaning 
DBPROMPTOPTIONS_WIZARDSHEET Prompt with Create New Data Link wizard. 
DBPROMPTOPTIONS_PROPERTYSHEET Prompt with Data Link Properties dialog box.     cSourceTypeFilter [in]    Count of elements in rgSourceTypeFilter. The only valid value is zero.    This is reserved for future use.    rgSourceTypeFilter [in]    This parameter is ignored unless cSourceTypeFilter is greater than zero. Otherwise, this parameter points to a valid array of DBSOURCETYPE values. If it is non-null, the providers presented to the user will be limited to those that match the SOURCE_TYPEs specified in rgSourceTypeFilter.    This is reserved for future use.    pwszszzProviderFilter [in]    A double null-terminated string of ProgIDs.    This parameter must be null, or point to a valid string. If it is non-null, the providers presented to the user will be limited to those that match the providers' ProgIDs specified in pwszszzProviderFilter. If only one provider is specified, and DBPROMPTOPTIONS_WIZARDSHEET is specified, the provider selection page is not displayed.    riid [in]    The requested interface for the data link returned in *ppDataSource.    ppDatasource [in, out]    A pointer to a data source object (DSO).    If *ppDataSource is null on entry, then Prompt generates a new DSO based on the information specified by the user, and returns a pointer to that DSO in *ppDataSource.    If *ppDataSource is non-null on entry, Prompt uses the properties returned by IProperties::GetProperties() as initial values. If the user selects a different provider, Prompt will release the original *ppDataSource and create a new data source. On exit, *ppDataSource will be set to a pointer to the interface specified by riid.     Return Code    S_OK    The method succeeded.    E_FAIL    A provider-specific error occurred.    DB_E_CANCELED    The user canceled the dialog.    E_NOINTERFACE    The data source did not support the interface specified in riid.    riid was IID_NULL.    *ppDatasource was not null and did not indicate an OLE DB data source generated from IDataInitialize or IDBPromptInitialize.    DB_E_NOAGGREGATION    pUnkOuter was not a null pointer and riid was something other than IID_IUnknown.    pUnkOuter was not a null pointer and the provider does not support aggregation.    E_INVALIDARG    ppDatasource was a null pointer.    cSourceTypeFilter was not zero and rgSourceTypeFilter was a null pointer.    An element in rgSourceTypeFilter was not a valid filter.    dwPromptOptions was an invalid value.    Comments    None.    Code Example    The following code fragment shows how a consumer might use IDBPromptInitialize::PromptDataSource to prompt the user for connection information:    // First CoCreate the OLE DB Service Component Manager
//    HRESULT               hr                    =S_OK;
IDataInitialize      *pIDataInitialize      =NULL;    hr = CoCreateInstance(
         CLSID_DataLinks, 
         NULL, 
         CLSCTX_INPROC_SERVER, 
         IID_IDataInitialize, 
         reinterpret_cast(pIDataInitialize));    // CreateDBInstance to instantiate previously stored provider
//    CLSID               clsidProvider     (GetProviderCLSID());
IDBProperties       *pIDBProperties   =NULL;    hr = pIDataInitialize->CreateDBInstance(
          clsidProvider,
          NULL,
          CLSCTX_INPROC_SERVER,
          NULL,
          IID_IDBProperties,
          reinterpret_cast(&pIDBProperties));    // Set some previously stored properties
//    ULONG             cPropertySets           (GetPropertySetsCount());
DBPROPSET         (*rgPropertySets)        (GetPropertySets());    hr = pIDBProperties->SetProperties(cPropertySets, rgPropertySets);    // Prompt the user to view/edit the connection information
//    IDBPromptInitialize   *pIDBPromptInitialize   =NULL;    hr = pIDataInitialize ->QueryInterface(
         IID_IDBPromptInitialize, 
         reinterpret_cast(&pIDBPromptInitialize));    hr = pIDBPromptInitialize->PromptDataSource(
         NULL,
         hWndParent,
         DBPROMPTOPTIONS_WIZARD,
         0, NULL, 
         NULL,
         IID_IDBProperties,
         &pIDBProperties);    
這是我從我舊舊的MSDN剪下來的,也許是我找錯了吧.. 不過在bcb上我不太會查資料說,有時候不一定知道全名 還有大大的用法我直接剪下貼上不能執行,我又找不到說明 可不可以再幫幫忙,謝謝!!
Delphi有包裝很多WinAPI,很多很複雜的都變得很簡單,PromptDataSource可能就是,你不妨Uses ADODB,然後打PromptDataSource(看有沒有跑出提示參數,或直接編譯看BCB懂不懂PromptDataSource,自己努力試試吧!
人生有夢,逐夢而行。 人若為善,福雖未至,禍已遠離。 人若為惡,禍雖未至,福已遠離。 http://www.taconet.com.tw/jieshu/
------
人生有夢,逐夢而行
人若為善,福雖未至,禍已遠離
人若為惡,禍雖未至,福已遠離
http://www.taconet.com.tw/jieshu/
pahan
一般會員


發表:1
回覆:7
積分:1
註冊:2002-09-16

發送簡訊給我
#13 引用回覆 回覆 發表時間:2002-09-23 12:07:02 IP:210.243.xxx.xxx 未訂閱
找到方法了:     
      TStartupInfo  StartupInfo;
      TProcessInformation  ProcessInformation;
     
      StartupInfo.cb=sizeof(TStartupInfo);
      StartupInfo.dwFlags=STARTF_USESHOWWINDOW;
      StartupInfo.wShowWindow=SW_NORMAL;
      if(CreateProcess(NULL, "Rundll32.exe C:\\PROGRA~1\\COMMON~1\\SYSTEM\\OLEDB~1\\OLEDB32.DLL,OpenDSLFile d:\\ConnectionSQL.UDL ",NULL, NULL, true, NORMAL_PRIORITY_CLASS, NULL, NULL,&StartupInfo, &ProcessInformation))
         WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
裡面比較要注意的就是rundll32.exe 只能使用dos時的命名規則,也就是目錄長度不能超過八位數,謝謝大家的指點。
scorpio
一般會員


發表:0
回覆:1
積分:0
註冊:2003-03-11

發送簡訊給我
#14 引用回覆 回覆 發表時間:2003-03-11 14:30:57 IP:163.28.xxx.xxx 未訂閱
以下是我用的方式... // 開啟 UDL DataLink File ,直到結束 Dialog為止 SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = Handle; ShExecInfo.lpVerb = "open"; ShExecInfo.lpFile = strDataLinkFileName.c_str(); ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = ""; ShExecInfo.nShow = SW_SHOWNORMAL; ShExecInfo.hInstApp = NULL; BOOL bRun = ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE); if (bRun == FALSE) { MessageBox( Handle, "資料庫設定失敗!!", "QuerySystem", MB_OK MB_ICONERROR); return; } //================================================= 只是不曉得有沒有可以直接開啟該Dialog的Function 並傳回設定字串....... 找好久都找不到~~
系統時間:2024-04-20 15:13:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!