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
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    8 Posts
    0 Views
    A
    This is probably what you need: #include #include #include #include int main(void) { char str[256] = "32 65 73 7 73"; int \*pn = NULL, n = 0; char\* \_tsn = strtok(str, " "); while (\_tsn != NULL) { int\* tmp = new int\[n + 1\]; if (pn != NULL) memcpy((void\*)tmp, pn, sizeof(int) \* n); tmp\[n++\] = atoi(\_tsn); if (tmp != NULL) pn = tmp; \_tsn = strtok(NULL, " "); } for (int i = 0; i < n; i++) printf("%d ", pn\[i\]); printf("\\n"); \_getch(); return 0; }
  • Estimate time of execution c-function execution

    linux algorithms performance help
    6
    0 Votes
    6 Posts
    2 Views
    A
    This is probably what you need: #include <time.h> #include <sys/time.h> #include <stdio.h> void test(){ int i;int s=0; for(i=1; i<1000000; i++){s+=sin(i)/i;} } int main(void) { clock_t time[2], timediff; float elapsed; time[0] = clock(); f1(); time[1] = clock(); elapsed = ((float)abs(time[0] - time[1]))/CLOCKS_PER_SEC; printf("Code executed in %f milliseconds.\n", elapsed); return 0; }
  • 0 Votes
    2 Posts
    0 Views
    A
    I don't know exactly, but it seems to me that you should never call SetFocus() method. Instead, we have to post WM_SETFOCUS message to the checkbox control as follows: HWND hCheckBoxWnd = NULL; if ((hCheckBoxWnd = ::GetDlgItem(hDlg,IDC_YOUR_CHECK_BOX_ID))) ::PostMessage(hCheckBoxWnd, WM_SETFOCUS, 0, 0); Actually, you should not send the message using SendMessage(...) Win32API function, all you have to do is to post the message using PostMessage(...) instead.
  • strcpy dilemma - it works half way

    visual-studio hardware tools help
    8
    0 Votes
    8 Posts
    0 Views
    A
    This should exactly work: #include #include int main(void) { char *Result = "Result init "; char Source[256] = "123"; char Destination[256] = "456"; Result = strcpy(Source, Destination); printf("Result = %s\\nSource = %s\\nDestination = %s\\n", Result, Source, Destination); return 0; }
  • 0 Votes
    3 Posts
    0 Views
    D
    Thanks it turned out the problem was that the directory that the Temporary Internet files were stored in no longer existed after the update to Windows 10. Trying to change this under the Control Panel application for Internet settings failed to change the directory as the one that it was trying to move the files from did not exist. The only way to correct the problem was to manually edit the registry key as explained here: https://msdn.microsoft.com/en-us/library/ms940828(v=winembedded.5).aspx
  • Temperature monitoring on an Android device

    android question linux iot
    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • ManabJB

    learning
    5
    0 Votes
    5 Posts
    0 Views
    U
    thanxxx to alert this
  • Complex code in conditionals

    help question discussion
    8
    0 Votes
    8 Posts
    0 Views
    S
    This is not too complex, but at the limit where I would consider breaking it up into multiple statements. That said, if that were a while condition, I might be more inclined to leave it like that, because (a) the increment might be considered part of the loop iteration, and (b) moving part of the condition might require more than one additional line (e. g. once before the start of the loop and once inside). Apart from that, I am more bothered with the naming ;P GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
  • Coloring scrollbar with DrawThemeBackground

    debugging help question
    8
    0 Votes
    8 Posts
    0 Views
    _
    I have tried also: HTHEME hTheme = OpenThemeData(m\_hWnd, L"SCROLLBAR"); // HTHEME hTheme = OpenThemeData(m_hWnd, L"WINDOW"); // HTHEME hTheme = OpenThemeData(m_hWnd, L"MFCGridCtrl"); if(NULL != hTheme) { if(WS_VSCROLL & GetStyle()) { SCROLLBARINFO si; si.cbSize = sizeof(SCROLLBARINFO); GetScrollBarInfo(OBJID_VSCROLL, &si); CRect rect(si.rcScrollBar); pDC->FillSolidRect(&rect, RGB(255, 255, 0)); HRESULT hRes = DrawThemeBackground( hTheme, pDC->GetSafeHdc(), SBP_UPPERTRACKVERT, SCRBS_NORMAL, &rect, NULL); TRACE("HRESULT: %d|%d: OK ? %d\n", hRes, S_OK, hRes == S_OK); } CloseThemeData(hTheme); } And the result are S_OK now, which is good, however, I have seen nothing colored ... strange ...
  • Dialog controls not showing up on a child dialog

    c++ question
    4
    0 Votes
    4 Posts
    0 Views
    K
    Its a MFC dialog based application. Main dialog is created when the application is created using "New Project" wizard and the child dialog is created by inserting a "Insert Dialog" in resource view and then adding dialog controls to it. PKNT
  • C++ reverse engineering

    c++
    2
    0 Votes
    2 Posts
    0 Views
    CPalliniC
    This is not the appropriate forum for such a post, please remove it.
  • Passing an "array" in C

    csharp data-structures c++ performance question
    20
    0 Votes
    20 Posts
    0 Views
    K
    I believe that's implementation defined. With my linux box I can use ulimit to set the size of the stack. By default it seems to be 8MB, but I can modify that upwards more or less as needed (obviously within memory limits of the system). I seem to recall that early C implementations were limited to returning basic types (e.g. int, double, char *, etc). gcc-5.2 still has a warning flag for aggregate returns - which suggests that other C compilers might still adhere to that.
  • Timer interrupt handler on SAM3x8e – Arduino Due

    hardware question help
    4
    0 Votes
    4 Posts
    0 Views
    CPalliniC
    You are welcome.
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • runtime error due to corruption of heap

    help
    5
    0 Votes
    5 Posts
    0 Views
    J
    This is usually sourced by writing to an array with an out of bound index. So you must check all your allocated arrays (which may include arrays that are allocated by library functions). Starting with your own ones, search for any call to new as array; e.g.: type arrayName = new type[size]; Then for each array check the accesses for invalid indexes (index < 0 or >= size). You can do this manually by reading your source or by guarding all accesses with assertions in debug builds: assert(index > 0 && index < arrayNameSize); arrayName[index] = someValue; Your posted code does not contain the allocation of most. So it can't be checked by us. But there are many candidates: boolArray and all arrays used inside the 'while (i < numHapticDevices)' loop (e.g. hapticDevices).
  • Convert to ASCII ?

    question lounge
    7
    0 Votes
    7 Posts
    0 Views
    CPalliniC
    If all you need is the ASCII character corresponding to the given integer than a cast is enough, e.g. printf("%c\n", (char) RANDOM);
  • strcat adding characters on SAM3x8e

    c++ question
    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    3 Posts
    0 Views
    J
    When the input data are 8 bit gray scale values just assign them to the R, G, and B values and set the aplha value to zero: // Assuming RGBA is an uint32_t / DWORD type and // *in an unsigned char / uint8_t pointer. RGBA *out = new RGBA[512 * 512]; for (unsigned i = 0; i < 512 * 512; i++) { out[i] = (in[i] << 16) + (in[i] << 8) + in[i]; }