How to call the dialog box for establishing a connection string in the program

zhaozj2021-02-11  172

Sometimes you need to use the connection string in the program, but it is possible to change it when configured, manually input is easy, with this dialog, everything is simple, but this dialog is not an API. In addition, I checked the MSDN and copying the West and copied the cop and copying myself. I have been in some of the following functions. The thing inside does not need to understand, put it with your Copy, you can use it, you can understand the best, find your mistake, please send emailto: fantong77@hotmail.com.

BOOL GetConnectString (TCHAR * lpszConnectString, HWND hWndParent) {CComPtr pIDBPromptInitialize = NULL; CComPtr pIDBProperties = NULL; CComPtr spDataInit = NULL; CComBSTR bstrConnectString; HRESULT hr; // Create an instance of the Data Links Component. hr = cocreateInstance (CLSID_DATALINKS, NULL, CLSCTX_INPROC_SERVER, IID_IDBPROMPTINIALIZE, (Void **) & pidbpromptinitialize; if (Failed (HR)) Return False;

// Prompt the user for the provider and initialization properties hr = pIDBPromptInitialize-> PromptDataSource (NULL, hWndParent, DBPROMPTOPTIONS_PROPERTYSHEET, 0, NULL, NULL, IID_IDBProperties, (IUnknown **) & pIDBProperties);. If (FAILED (hr)) return FALSE ; hr = CoCreateInstance (CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, IID_IDataInitialize, (void **) & spDataInit); if (FAILED (hr)) return FALSE; hr = spDataInit-> GetInitializationString (pIDBProperties, true, & bstrConnectString); if (FAILED (hr )) RETURN FALSE; LSTRCPY (LpszConnectString, (Char *) _ BSTR_T (BSTRCONNECTSTRING); RETURN TRUE;

}

Parameter description, the return value is false, the user cancels

The second is OUT, enter the connection string

Third place in, parent window

Remember to initialize COM first

转载请注明原文地址:https://www.9cbs.com/read-5371.html

New Post(0)