question

DavidHoffman-6474 avatar image
0 Votes"
DavidHoffman-6474 asked Castorix31 commented

SQL Compact Edition 4.0

I need help in writing code behind for my UWP WinRT C++ app. Specifically which namespace do I use, do I need to specify a Ref to a .winmd file, and all the related API calls one might want to code to get info from the dB. I have looked and found some stuff for C# but I need it for C++. I hate translating from C#. Thanks.

sql-server-generalwindows-uwpc++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
1 Vote"
Castorix31 answered Castorix31 commented

In C++, I use OLEDB, like : Establishing a Connection to a Data Source

For SQLCE, I replace "CoCreateInstance(CLSID_SQLNCLI..."

by :

 // [C++] [Language]
 // Conformance mode : No (/Permissive)
    
 #include "sqlce_err.h"
 #include "sqlce_oledb.h"
 #include "sqlce_sync.h"
    
 IDBInitialize* pDBInitialize = NULL;
 IClassFactory* pClassFactory = NULL;
 HRESULT DllCoCreateInstance(HMODULE hModule, REFCLSID rclsid, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppv);

then :

 HRESULT hr;
 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
 HMODULE hModule = NULL;
 // sqlceoledb40.dll deployed in the .exe directory (with sqlceer40EN.dll, sqlceer40FR.dll, sqlceqp40.dll, sqlcese40.dll)
 hModule = LoadLibrary(L"sqlceoledb40.dll");
 hr = DllCoCreateInstance(hModule, CLSID_SQLSERVERCE, NULL, IID_IDBInitialize, (void**)&pDBInitialize);

with the utility function :

 HRESULT DllCoCreateInstance(HMODULE hModule, REFCLSID rclsid, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppv)
 {
     HRESULT hr = S_OK;
     if (hModule == NULL)
         return E_INVALIDARG;
     BOOL(WINAPI * DllGetClassObject)(REFCLSID, REFIID, LPVOID) = NULL;
     (FARPROC&)DllGetClassObject = GetProcAddress(hModule, "DllGetClassObject");
     if (DllGetClassObject == NULL)
         return HRESULT_FROM_WIN32(GetLastError());
     hr = DllGetClassObject(rclsid, IID_IClassFactory, &pClassFactory);
     if (FAILED(hr))
     {
         return hr;
     }
     return pClassFactory->CreateInstance(pUnkOuter, riid, ppv);
 }


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have added the code above to my project, but I get several errors. The big one is VS does not know where the 3 .H files are, and neither do I. A lot of the errors I can solve by myself if I knew where you got this code in the first place. Steer me in the right direction and I can do this. Thanks for helping so far. Is there an API that I need to install? I only added the VS plugin and the installer that contained all the .DLLs, but no .H files with the .DLLs.

0 Votes 0 ·

I don't remember from where I got the headers...

I uploaded them : sqlce_headers.zip


0 Votes 0 ·

Thanks for uploading them. I still wonder if they are from some API that I need to install, so I am still looking for more clues. Thanks.

0 Votes 0 ·
Show more comments