How to Get Printer Information in C++|How to convert char * to BSTR* in C++
In this blog post, we will discuss how to get printer information in C++. We will use the following code: C++ STDMETHODIMP CSimpleCom::Get_PrinterInfo (BSTR* InfoBuffer) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: Add your dispatch handler code here try { int a = 0 ; char * str = ( char *) memset ( malloc ( 1 ), '\0' , 1 ); a = EV_Get_PrinterInfo(str); if (a == 0 ) { int len = strlen (str) + 1 ; OLECHAR* wstr = new OLECHAR[len]; MultiByteToWideChar(CP_ACP, 0 , str, len, wstr, len + 1 ); *InfoBuffer = SysAllocString(wstr); } } catch (...) { } return S_OK; } Use code with caution. Learn more content_copy Explanation: The first thing we do is declare a function called Get_PrinterInfo() . This function takes a pointer to a BSTR string as its parameter. The BSTR string will be used to store the printer information. Next, we use the AFX_MANAGE_STATE() macro to manage the state of the application. This macro is nec...