SQL Compact Edition 4.0

David Hoffman 121 Reputation points
2021-10-21T21:42:48.423+00:00

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.

Universal Windows Platform (UWP)
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,758 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,537 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,741 Reputation points
    2021-10-22T07:17:23.967+00:00

    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);  
    }  
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful