Posts

Showing posts from August, 2023

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...

ATL COM Compiler Error C2259

Image
  ATL COM Title: ATL COM Error 2259: Resolving with the Power of CHAR Introduction: In the realm of ATL (Active Template Library) COM development, encountering errors is a natural part of the journey. One such enigma is ATL COM Error 2259, which cryptically states "Cannot Instantiate Abstract Class." In this blog post, we embark on a quest to decode this error and unveil a unique solution that involves harnessing the power of the CHAR datatype. Our journey is inspired by a real-life scenario faced by a seasoned developer, Alex. Decoding Error 2259: "Cannot Instantiate Abstract Class" holds a key message: an attempt to create an instance of an abstract class, which by design, lacks complete implementations for its methods. Understanding this concept is pivotal to unlocking the solution. The Charmed Encounter: Let's rejoin Alex on his quest. In his investigation of "SimpleATLCom," Alex discovers a fascinating connection between the error and the datatype...