Skip to content

C / C++ / MFC

C, Visual C++ and MFC discussions

This category can be followed from the open social web via the handle c-c-mfc@forum.codeproject.com

111.5k Topics 465.7k Posts
  • 0 Votes
    4 Posts
    0 Views
    M
    Thanks Leon. It worked. Thanks, Lakshmi
  • SOLVED CMake whose "source directory" ?

    question data-structures
    8
    0 Votes
    8 Posts
    0 Views
    V
    I have no idea how my initial post got duplicated. My apology to forum Vaclav
  • CMake - syntax error ?

    help tutorial question announcement
    5
    0 Votes
    5 Posts
    0 Views
    J
    The syntax error is: The program processing the file is not able to parse the command cmake_minimum_required(VERSION 3.5). The reason is: You have pasted the command into the file opencv.sh which is processed by the shell (the Unix command line interpreter; see Unix shell - Wikipedia[^] ). But it should be pasted into the file CMakeLists.txt which is processed by CMake. The solution (see my initial answer): Quote: So you have to add the command to the CMake file CMakeLists.txt. instead of opencv.sh.
  • CMake - syntax error ?

    help tutorial question announcement
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • Eclipse IDE GCC linker options ?

    question visual-studio help
    16
    0 Votes
    16 Posts
    0 Views
    L
    And that is how it does work. You just need to ensure that your options and parameters are specified correctly.
  • Need Help in writing a Windows device driver

    tutorial c++ json help
    5
    0 Votes
    5 Posts
    0 Views
    L
    CmyLife wrote: Is is possible to get the names of the kernel system calls? Those aren't included in the code. You can use "depends" to find the address of the method you're looking for. See WinApiOverride Frenquent Asked Questions[^] and Dependency Walker (depends.exe) Home Page[^] Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
  • Sharing some humour

    data-structures performance career
    8
    0 Votes
    8 Posts
    0 Views
    L
    Hi, I waited until the thread went beyond the first page to further engage with you. I can tell you why your employer has this requirement. This is common on mission-critical software. Exceptions and Stack Unwinding in C++[^] If you allocate memory on the stack... and a recoverable exception occurs in your thread... the memory is correctly released during stack unwinding. If you allocate memory on the heap and a recoverable exception occurs in your thread... the memory is not released and now your application potentially has a resource leak. leon de boer wrote: As they said you can't hack it and is guaranteed to perform error-free, that isn't a claim it's a provable fact. This is not correct. I have met both Bryan Parno[^] and Jeannette Wing[^] and I was present at the 2014 presentation on campus at Redmond. Yes, small sections of logic can be statistically proven to be secure. It would not be correct to make the claim of "guaranteed to perform error-free, that isn't a claim it's a provable fact" If I were to assign a confidence level to what they have achieved I would say "High Confidence". Best Wishes, -David Delaune
  • C++, Microsoft's CoreRT turns C# into cross-platform C++

    csharp c++ dotnet com iot
    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    7 Posts
    0 Views
    L
    Member 12335695 wrote: Program: C:\Windows\system32\mfc120ud.dll File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\barstat.cpp Line: 99   For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.   (Press Retry to debug the application) f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winfrm.cpp(1628) : AppMsg - Warning: no message line prompt for ID 0xE001. This means that your status bar is missing an ATL/MFC resource string for the ATL_IDS_IDLEMESSAGE. Add this to your .RC resource file: STRINGTABLE BEGIN ATL_IDS_IDLEMESSAGE "Ready" END You may be missing other resource strings. Best Wishes, -David Delaune
  • 0 Votes
    4 Posts
    1 Views
    B
    thank you all very much!!!
  • Save the image from window buffer

    question graphics
    2
    0 Votes
    2 Posts
    0 Views
    L
    That is all you need .. you can then get the window size RECT r; GetWindowRect(hWnd, &r); int Wth = r.right - r.left; int Ht = r.bottom - r.top; You also have the wonderful function CreateDIBSection which just needs a DC CreateDIBSection function (Windows)[^] You will need to allocate memory to hold the bits. That size is slightly tricky it depends on what color depth you are going to ask for in bits. Typically you want RGB24 or RGB32 and the size also needs to be aligned to a 4 byte boundary. Anyhow long story short its a funny maths calc and we need to setup a bitmap header info for the call ... Lets do 24 bit colour. BITMAPINFOHEADER BMIH; BMIH.biSize = sizeof(BITMAPINFOHEADER); BMIH.biBitCount = 24; BMIH.biPlanes = 1; BMIH.biCompression = BI_RGB; BMIH.biWidth = Wth; BMIH.biHeight = Ht; BMIH.biSizeImage = ((((BMIH.biWidth * BMIH.biBitCount)+ 31) & ~31) >> 3) * BMIH.biHeight; See that funny calc at end well BMIH.biSizeImage now has the memory size you need to allocate. So allocate it and then call CreateDIBSection char* myBits = malloc(BMIH.biSizeImage); CreateDIBSection(hDC, (CONST BITMAPINFO*)&BMIH, DIB_RGB_COLORS, (void**)&myBits, NULL, 0); myBits now has all your image data from the DC now all you need to do is save it!!!! For a BMP file that is trivial FILE *pFile = fopen( /* some Name */, "wb"); BITMAPFILEHEADER bmfh; int nBitsOffset = sizeof(BITMAPFILEHEADER) + BMIH.biSize; LONG lImageSize = BMIH.biSizeImage; LONG lFileSize = nBitsOffset + lImageSize; bmfh.bfType = 'B'+('M'<<8); bmfh.bfOffBits = nBitsOffset; bmfh.bfSize = lFileSize; bmfh.bfReserved1 = bmfh.bfReserved2 = 0; // Write bitmap file header UINT nWrittenFileHeaderSize = fwrite(&bmfh, 1, sizeof(BITMAPFILEHEADER), pFile); // Write bitmap info header UINT nWrittenInfoHeaderSize = fwrite(&BMIH, 1, sizeof(BITMAPINFOHEADER), pFile); // Write our data we got back UINT nWrittenDIBDataSize = fwrite(myBits, 1, lImageSize, pFile); // Close the file fclose(pFile); Now don't forget to free myBits when you are done that is alot of memory to bleed if you forget :-) In vino veritas
  • 0 Votes
    15 Posts
    1 Views
    F
    I am modifying the Hercules mainframe emulator code I have created a child Process a Windows MFC Program Basically the data shared between all of the threads is stored in a DLL named sysblk Thanks
  • C programming Determine Students grade

    css
    2
    0 Votes
    2 Posts
    0 Views
    L
    You need to hit the books or web lessons on C again. Your 3 statement inputs look good ... sorry that is it :-) Your printf statement is garbage hit the web or books and look up the words "formatted output of printf" and look at what %c means. However you have done absolutely nothing with the inputs to even think about calling that. What we are saying is you need to call a function between the last input and trying to print anything ... so scanf ("%d", &score3); //... You need a function call in here to do something with the scores and then fix the print below printf("The grade is: %c\n", score1, score2, score3); You even have the text that boldly says "// Function declarations" only you don't have anything there you just drop straight into main. Let me guess that was a hint in the template they gave you and you don't even get what it means? ScoreToGrade which was obviously was intended as your function is hanging out way down the bottom. You need to either forward declare it where you boldly declare you are going to have "// Function declatations" or move it up to there. So it's a cut and paste job or look up how to forward declare a prototype. Final problem // Local Declarations int temp = 0; It says it is local it is in fact a global variable ... you need to work out why. In vino veritas
  • Using COM in DLL called by .Net application

    csharp question wpf com sysadmin
    6
    0 Votes
    6 Posts
    0 Views
    L
    Thanks for the comments. I have tested using a simple Win32 C++ console application to drive our DLL, and it works fine when using the worker thread to invoke COM commands to the third party component. So clearly this is something to do with the .Net application. Okay, I have solved it. A COM STA uses Windows messages to serialise access to the COM object which might not be thread safe. So when I created a worker thread, the main thread then hung waiting for the worker thread to finish, but it never did, as the main thread hanging blocked the message pump! Instead of the main thread waiting, I now make it periodically run a message pump to ensure that messages are process. That has solved the problem. Yikes. I hate COM! Thank you for your helpful post. Added later: I have also looked into removing the worker thread and marshalling the COM interfaces across threads and this works. It has the advantage that I do not have to mess around with a message pump, which is akin to spinning the tyres.
  • 0 Votes
    3 Posts
    0 Views
    L
    Explicit and volatile you need to know, if you are seen using mutable in C++ we put you up against the wall and shoot :-) There are a couple of places you need volatile the two main ones are in multitasking code and interfacing to physical hardware. What volatile tells the compiler the result at that address can change between uses of it ... so it stops the optimizer assuming the value hasn't changed between uses of that address. Imagine the situation you have code that reads the port of a timer at an address. Then you do some other stuff not touching the port address and then you go an read the port again. Now if you are dealing with memory the two reads will have the same value as the code between the two reads didn't touch the port. So an optimizer might well conclude it can remove the second read and just hold the first read value. Only in reality the timer values ticks because it's hardware and so we need the second read to occur it can't be optimized. The same situation occurs in multitasking, memory that our own code didn't touch can change. So volatile is about making sure the optimizer doesn't shortcut stuff assuming just because the code hasn't touched it, that it hasn't changed. So any variable marked with volatile will have any action on that variable not subject to optimization. Explicit is when you want the compiler to stop being smart and convert types for you and pretending it's GWBASIC :-) It used to happen mostly on class/object code that a constructor for example would take a string as a parameter. If you gave it an integer it would automatically know to convert the integer to a string, which is pretty cool sometimes. Other times it leads to a complete and utter bug because you didn't allow for it. So if you tell the compiler you want explicit it turns off the GWBASIC parser and stops the conversion it will throw an error instead. Mutable is one you will rarely if ever need and if you do need it most of us will argue your code is badly organized or you are super lazy and dangerous. The better name for it would be cached or stencil playtime. So you have a constant or someone passes you in a constant, but you just want to change it I mean string "Drive A" is so close to "Drive B". You declare it mutable you can now play around with the constant it wont change the real constant just your local play copy. It's not something to encourage in that usage. The only real valid use of the directive is when you really are dealing with a real cache such as synchronization objects like mutexes &
  • Please help

    game-dev help question
    4
    0 Votes
    4 Posts
    0 Views
    A
    thanks a lot bro .. i think that will be so expensive for me .. because i am Arabian .. with dollars will be higher per month ... i will try software can control traffic and filtering as i can .. if you have suggestion for software that will be awesome ... thanks again
  • 0 Votes
    5 Posts
    1 Views
    D
    One issue: I would define a virtual destructor for each interface. This allows you to delete an instance given a pointer to its interface. If you are using c++ interfaces to implement something like COM, you may wish to disregard this advice. If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill
  • Mouse out of dialog

    question debugging
    7
    0 Votes
    7 Posts
    0 Views
    _
    Kindly thank you all of you, I solved my problem. It is always a pleasure to talk here ! I am trying to create a graphic menu, a menu that is in fact a CDialog, created in non modal way.
  • 0 Votes
    10 Posts
    1 Views
    L
    Okay lets first deal with your misconceptions Windows console windows do have a window handle it just has a special function to get it because it isn't present by default because you start with main not winmain and main has no position for it on it's parameters which are arguments. GetConsoleWindow function (Windows)[^] You can also directly pull the message handler if you want to just provide your own that looks like this WNDPROC ConsoleWindow = NULL; static LRESULT CALLBACK MyWndProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam) { // Process your message here if (ConsoleWindow) return CallWindowProc(ConsoleWindow, Wnd, Msg, wParam, lParam); // Call back old handler return(0); } // Usually first thing in main HWND hWnd = GetConsoleWindow(); ConsoleWindow = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (LONG)MyWndProc); However since Win95 we tend not to do that anymore because there is a much easier way with a special class called Message-Only Windows. There are even a couple of articles on using them in the code project archives but it's just like any normal window just it has no visible parts. The 3rd alternative is you make a normal windows program and create a console window from the launch using AllocConsole. AllocConsole function (Windows)[^] Lots of science and maths guys do this so they can dump data out onto the console window while running there graphics. You do not have to have a graphics window however you can simply use the stdin and stdout ... here is the simplest sample. Compile it as a standard windows GUI project. So again in this sample you have a standard message queue available and a console window. #include #include int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DWORD charsRead = 0; TCHAR keyBuffer[100]; AllocConsole(); HANDLE myConsoleHandle = GetStdHandle(STD\_OUTPUT\_HANDLE); DWORD cCharsWritten; TCHAR\* str = TEXT("Hello I am the console\\r\\n"); WriteConsole(myConsoleHandle, st
  • 0 Votes
    1 Posts
    0 Views
    No one has replied