Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all 3027 articles
Browse latest View live

MFC Dialog Application Help

$
0
0
Completely new to C++ and have been given a task that includes creating an application that uses CString data from a completely separate .h file.
The CStrings consist of info that I need to be able to copy to the clipboard, then be able to paste that text into word etc. I have set up a button in the application so when that button is pressed it executes what I want it to do (read the CString data and copy it to the clipboard).
For a person of my skill level this is difficult and my colleagues do not have the time to support me on this learning project so I thought I could get some advice and pointers here. Any help would be greatly appreciated. I am an apprentice working in software for 2 months.

Kind regards,
Luke

Code review request for displaying UI over the logon screen

$
0
0
Hi everyone:

I have a Windows service written in C++/WinAPI that runs in a local-system context. The service may perform some configurable power actions (such as put the system into sleep mode) depending on user inactivity and other parameters related to my app. But before performing these actions I would like to show a user warning in a form of a simple UI window with a countdown.

Displaying such warning UI when an interactive user is logged on to the workstation is not an issue and is outside of the scope of this question.

The issue comes up when I need to display my warning UI over a logon screen in 2 basic scenarios:

1. When there's no logged on interactive users (say, when the system just boots up and before any user had a chance to log in.)

2. When the workstation is locked by a user, either by selecting Start -> (Power Button) -> Lock workstation, or by hitting Ctrl+Alt+Delete on the keyboard, etc.

I was able to come up with the following code (that is called from within my service) that works well in the (1) scenario. Just as a proof of concept I'm using Windows calculator in place of my user-mode process that would normally display the warning UI. It produces something like this:

Name:  CfZiA.png
Views: 12
Size:  85.1 KB

Here's the pseudo-code that I'm using:

Code:

//The following method can be used to launch a GUI process
//in a logon desktop from a local system service.
//INFO: Error checks are omitted for brevity!

DWORD dwActvSessID = WTSGetActiveConsoleSessionId();

HANDLE hSelfToken = NULL;
OpenProcessToken(::GetCurrentProcess(), TOKEN_ALL_ACCESS, &hSelfToken);

HANDLE hTokenNew = NULL;
DuplicateTokenEx(hSelfToken, TOKEN_ASSIGN_PRIMARY | TOKEN_ALL_ACCESS, NULL, SecurityIdentification, TokenPrimary, &hTokenNew);

SetTokenInformation(hTokenNew, TokenSessionId, &dwActvSessID, sizeof(dwActvSessID));

//I'm not sure about the need of this duplication???
HANDLE hToken2 = NULL;
DuplicateHandle(::GetCurrentProcess(), hTokenNew, ::GetCurrentProcess(), &hToken2, 0, FALSE, DUPLICATE_SAME_ACCESS));

LPVOID pEnvBlock = NULL;
CreateEnvironmentBlock(&pEnvBlock, hToken2, FALSE);

STARTUPINFO si;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.lpDesktop = L"Winsta0\\Winlogon";

PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));

TCHAR pBuffCmdLine[MAX_PATH];
pBuffCmdLine[0] = 0;

StringCchCopy(pBuffCmdLine, MAX_PATH, L"calc.exe"); //As a test launch the calculator

ImpersonateLoggedOnUser(hToken2);

bResult = !!CreateProcessAsUser(
        hToken2,            // client's access token
        L"calc.exe",        // file to execute
        pBuffCmdLine[0] != 0 ? pBuffCmdLine : NULL,    // command line
        NULL,              // pointer to process SECURITY_ATTRIBUTES
        NULL,              // pointer to thread SECURITY_ATTRIBUTES
        FALSE,            // handles are not inheritable
        NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT,  // creation flags
        pEnvBlock,              // pointer to new environment block
        NULL,              // name of current directory
        &si,              // pointer to STARTUPINFO structure
        &pi                // receives information about new process
    );

RevertToSelf();

if(bResult)
{
    //Can wait on process handle in 'pi.hProcess' if needed...
}

if(pi.hProcess)
    CloseHandle(pi.hProcess);
if(pi.hThread)
    CloseHandle(pi.hThread);

if(pEnvBlock)
    DestroyEnvironmentBlock(pEnvBlock);

CloseHandle(hToken2);
CloseHandle(hTokenNew);
CloseHandle(hSelfToken);

But the issue with the code above is that it does not fully work in the (2) scenario, or when my 'dwActvSessID' variable is 1 and up, or when there's a logged in interactive session. What happens in that case is that the calc.exe process starts up and runs but it's UI is not visible above the logon desktop UI. Here's the screenshot from the TaskManager, and as you see the calc.exe is running, in this case as a SYSTEM account:

Name:  3.png
Views: 11
Size:  39.5 KB

There's a definitely some mix-up with the desktop that my UI process is started under.

Any idea what am I missing here?


PS. Just as an interesting observation, if I replace "calc.exe" with any non-GUI process, such as "cmd.exe" its window does show up above the logon screen, as I would expect it. Here's a screenshot:

Name:  2.jpg
Views: 12
Size:  25.8 KB
Attached Images
   

Two pieces of good news

Converting toolbar into ribbon

$
0
0
I have MS Project Addin developed using VC++ ATL COM. Now while implementing it in MS Project 2013, I want to convert the toolbar into ribbon. How can I accomplish this? Is there a utility, that can convert toolbars into ribbon, keeping the functionality intact?

Problem to read value from a file in visual studio 2015 C++

$
0
0
Hi,

I need to read a value from a file. My file is formatted and I need to read lines like this:
- { x:2.5309753417968750e-12

To do this, I've done this (totot is my ifstream descriptor)
string name;
totot >> name; // detection of -
totot >> name; // detection of {
char name2[2]; //
totot >> name2; // to remove x:
double x;
totot >> x;

It works great for the beginning of my line, but not for x.

If a add an extra space after x: it works !

How can I modify this to be able to read my x value ?

Thanks

idle process

$
0
0
I couldn't find anywhere any information on how to run a process or thread in the idle (power saving) processor speed. Maybe someone here knows how-to or at least some keywords?

The basic idea is:
Imagin your laptop runs on batteries and you have sometimes tasks to execute. These tasks are not time critical, but needs to be done at some point (e.g. auto-save). The CPU is running all the time anyway, maybe just spinning in the idle 'process'. I'd like to somehow run a thread or process without bumping up the CPU state or even trigger some turbo/overclocking.

I know I can run low priority threads that will be executed if there is no any higher priority thread running, but this causes my CPU to still run at full speed. I know I can "Sleep" to drop into power saving if I don't need the thread, but I actually need the thread to run, I just don't care how slow it runs.

I've found WinAPIs to set a thread state to disable power saving (e.g. display always on) and I've found some APIs to enforce some a power saving scheme that you usually setup by hand (e.g. balances, maximize performance, maximize power saving), but those affect the whole system and I really don't want to enforce a change in the settings.


hopefully I could express what I'm aiming for, I'm sure I'm not the first that wants this, but I just cannot find a solution in google nor here in forum (after crawling through some pages of the search result).

[RESOLVED] CaptureStackBackTrace

$
0
0
Using MSVC-8 I need to compile a module which calls CaptureStackBackTrace. There's no declaration for it in WinBase.h but the function itself does seem to exist in kernel32.lib (although the actual implementation seems to be called RtlCaptureStackBackTrace). I figured that if I provide my own declaration, then link to kernel32.lib it should all work. Here's how things look in my source file:-

Code:

#define CaptureStackBackTrace RtlCaptureStackBackTrace

__declspec(dllimport) USHORT WINAPI CaptureStackBackTrace (
          ULONG  FramesToSkip,
          ULONG  FramesToCapture,
          PVOID  *BackTrace,
          PULONG BackTraceHash
        );

void the_function_that_needs_it ()
{
        const size_t levels = 62;
        void* stack [levels];
        unsigned short frames;

        frames = CaptureStackBackTrace(0, levels, stack, NULL);

        // rest of the code...
}

However... even after linking to kernel32.lib my linker tells me:-

Quote:

unresolved external symbol "__declspec(dllimport) unsigned short __stdcall RtlCaptureStackBackTrace(unsigned long,unsigned long,void * *,unsigned long *)" (__imp_?RtlCaptureStackBackTrace@@YGGKKPAPAXPAK@Z) referenced in function "void the_function_that_need_it(void")
Am I doing something wrong?? In the past I've sometimes found these problems to be due to calling conventions etc - but I've tried various experiments without success. I can also see that (in kernel32.lib) the actual function seems to be preceded by an underscore. So I tried:-

Quote:

#define CaptureStackBackTrace _RtlCaptureStackBackTrace

but that didn't work either... :cry:

Crash Reading & Writing More Files

$
0
0
Hi. I have a program that reads from a couple large files and extracts select smaller files. The code below was working until I went from 22 extractions to 56. And this number may increase in the future.

At first, I thought one (or more) of the new entries had an error. However, the program works when I removed either the original half or the new half of entries.

Since it crashes with all entries, this leads me to believe that the problem is the volume of extractions and that the code needs to be optimized in some way.

I tried added pauses between extractions, but it still crashes immediately upon running. So I'm not sure if that indicative of something else.

Here is a snippet of the code...

Code:

#include <iostream>
#include <fstream>
#include <windows.h>

using namespace std;

int main(){

//Still crashes if pause is before all this code.
//std::cin.get();

ifstream infile001 ("Source1.xxx", ifstream::binary);
ofstream outfile001 ("001.yyy", ofstream::binary);
infile001.seekg(0x2a00000);
char buffer001[15000];
infile001.read (buffer001,15000);
outfile001.write (buffer001,15000);
outfile001.close();
infile001.close();

ifstream infile002 ("Source1.xxx", ifstream::binary);
ofstream outfile002 ("002.yyy", ofstream::binary);
infile002.seekg(0x3f00000);
char buffer002[27000];
infile002.read (buffer002,27000);
outfile002.write (buffer002,27000);
outfile002.close();
infile002.close();

//And so on...

return 0;

}

I've also tried making a extract call out of this code, but haven't been successful. Unless the code to fix this is more complex than the above code, I'm okay with not making an extract call as long as everything works. Any help is appreciated. Thanks!

[RESOLVED] EnumChildWindows & FindWindow doesn't work MFC but works Console

$
0
0
Hello
I'm trying to get the message from a static text in another application. I have this code which works perfectly in console application:
Code:

BOOL CALLBACK EnumChildProc2(HWND hwnd, LPARAM lParam) {
        counter2++;
        if (counter2 == 6) // counter 6 is the static text child
        {

                cout << "hwnd_Child 6 = " << hwnd << endl;
                HWND hand = (HWND)hwnd;

                char szBuf[2048];
                LONG lResult;
                lResult = SendMessage(hwnd, WM_GETTEXT, sizeof(szBuf) / sizeof(szBuf[0]), (LPARAM)szBuf);
                printf("%s", szBuf); // it prints the message correctly
        }
        return TRUE;
}

int main() {
EnumChildWindows(FindWindow("#32770", "Unable to Write"), EnumChildProc2, 0);
}

It works very well in console application but it seems that bool callback function doesn't work as i need in MFC application . This is the code i used in MFC:

Code:

BOOL CALLBACK EnumChildProc2(HWND hwnd, LPARAM lParam) {
        counter_Child6++;
        if (counter_Child6 == 6)
        {
                HWND hand = (HWND)hwnd;
               
                char szBuf[2048];
                LONG lResult;
                lResult = SendMessage(hwnd, WM_GETTEXT, sizeof(szBuf) / sizeof(szBuf[0]), (LPARAM)szBuf);
                CString ssString;
                ssString.Format(_T("%s"), szBuf);
                AfxMessageBox(ssString);
        }
        return TRUE;
}

CWnd *pWnd = FindWindow(_T("#32770"), _T("Unable to Write"));
        if (NULL != pWnd)
        {
                listControl1.InsertItem(0, _T("Window Exists"));
                EnumChildWindows((HWND)pWnd, EnumChildProc2, 0); //this function doesn't afxmessagebox anything
        }
        else
        {
                listControl1.InsertItem(0, _T("Does not Exists"));
        }

Any help would be greatly appreciated! Thanks

noexcept

$
0
0
I'm building a popular gtk library called glibmm. Effectively, it's a C++ wrapper around the libglib toolset. Some classes used to have member functions declared like this:-

Code:

void whatever_function() throw();
but in the latest version, that's been changed to this:-

Code:

void whatever_function() noexcept;
I can't find anywhere where noexcept gets defined to throw() - so is this part of some newer C++ specification? (C++11 maybe??)

[RESOLVED] noexcept

$
0
0
I'm building a popular gtk library called glibmm. Effectively, it's a C++ wrapper around the libglib toolset. Some classes used to have member functions declared like this:-

Code:

void whatever_function() throw();
but in the latest version, that's been changed to this:-

Code:

void whatever_function() noexcept;
I can't find anywhere where noexcept gets defined to throw() - so is this part of some newer C++ specification? (C++11 maybe??)

I cannot input enum class value

$
0
0
I have defined a enum class:

Code:

enum class Genre
{
        fiction, nonfiction, periodical, biography, children
};

And another class:

Code:

class Book
{
public:
        string f_title() { return title; }
        string f_author() { return author; }
        string f_isbn() { return isbn; }
        Genre f_genre() { return g; }
        int f_day();
        int f_month();
        int f_year();
        Book(string tit, string aut, string isbn, Genre g);
        Book(string tit, string aut, string isbn);
        Book();
        class Invalid {};
private:
        string isbn, title, author;
        int day, month, year;
        Genre g;
};

I am stuck because I am not able to directly input values because I am not able to correctly set helper function. I had to create two different ones:

Code:

istream& operator>>(istream& is, Book& n)
{
        string title, author, isbn;

        getline(is,title);
        getline(is,author);
        getline(is,isbn);
        isbn.resize(7);

        if (!is) return is;

        n = Book{ title,author,isbn };

        return is;
}

istream& operator>>(istream& is, Genre& g)
{
        int i;
        is >> i;
        g = (Genre)i;

        return is;
}

but my program skips the Genre helper function and returns to me the default value "N/A".

How can I fix it?

Thanks!

Encrypt/Decrypt Problem

$
0
0
Hi,
I was used the link - Encrypt/Decrypt a String

I have a problem in my application.

I was encrypt a string using the above link with a key from PC1.
i like to decrypt the encrypted string(from PC1 - decrypt using the same key) from PC2.

If i process Encryption/Decryption in a same PC, working correctly.
but different PC, problem occurred.

pls, clear me.

Help on asynchronous WinInet or WinHttp

$
0
0
Hi, Folks,

I would like to create a http connection and send over multiple asynchronous requests and then handle the responses in a callback function.

How should I identify the request that each response corresponds to?

Thanks,

CR

SendMessage WM_CLOSE stops the loop

$
0
0
Hello
I have a list control with 10 items. Each item is a window that i'm trying to open and close.
It works well for windows that have only one OK button or none at all but if the window has YESNO buttons and an edit - then the loop stops but don't understand why ?:confused:
To find window and close it i use :
Code:

StepsToTry *st = (StepsToTry *)param;
HANDLE hwnd = FindWindow(L"#32770", L"Window Name");
HANDLE hwnd2 = FindWindow(L"#32770", L"Window Name with edit and many buttons");
while (hwnd == 0 && hwnd2 ==0)
        {
                Sleep(1000);
hwnd = FindWindow(L"#32770", L"Window Name");
hwnd2 = FindWindow(L"#32770", L"Window Name with edit and many buttons");
} // if any of these 2 windows pop up then ...

if (hwnd != 0) // if window pop up
        {
                st->messageback = "window 1 popped up";
                AfxGetMainWnd()->SendMessage(MESSAGEBACK_MSG, (WPARAM)0, (LPARAM)st);
                HWND HWnd = ::FindWindow(_T("#32770"), _T("Window Name"));
                ::SendMessage(HWnd, WM_CLOSE, 0, 0); // tell window to close
               
        }
        if (hwnd2!=0) {
                st->messageback = "window 2 popped up";
                AfxGetMainWnd()->SendMessage(MESSAGEBACK_MSG, (WPARAM)0, (LPARAM)st);
                HWND HWnd2 = ::FindWindow(_T("#32770"), _T("Window Name with edit and many buttons"));
                ::SendMessage(HWnd2, WM_CLOSE, 0, 0); //tell window to close
        }

The loop is:
Code:

int nCount = ts->dlsg->listControl1.GetItemCount();
        for (int x = 0; x < nCount; x++)
        {
StepsToTry *param = new StepsToTry;
step2CheckIfWindowOpenHandle = AfxBeginThread(step2CheckIfWindowOpen, param, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
                step2CheckIfWindowOpenHandle->ResumeThread();
        WaitForSingleObject(step2CheckIfWindowOpenHandle->m_hThread, INFINITE); // wait step 2 to finish
}

If there is a window with edit control and more than 1 button then the loop stops for some reasons, however if i afxmessagebox() after sendmessage to wm_close and then click the ok button in message box - in this case the loop continues.
Any help would be greatly appreciated
Thank you

exponential format

$
0
0
When the function DoDataxchange() asign a value to an edit control, an this value is nearly Zero, it could write a infinitesimal value in exponential format, like this -4.2678911233e-19.
How can I avoid this? I want that write 0.0 or at least 0.00000000000000426.

Is necessary do it for any edit control, or can i configure all the application, and this Works in every edit control?


Can someone help me, Thanks a .

PERE

How to debug memory allocation

$
0
0
Using VS C++ 2010 on Windows 7. Have a program that goes through a procedure of 40 loops. There are 10 modules in each loop that use GlobalAlloc to allocate 768 bytes of memory. On each loop, the memory is GlobalRealloc(ed) with an additional 768 bytes each time. Once the last loop is completed GlobalFree is used to free the memory for every module. However, it I leave the program running and attempt to run the procedure again, there is a failure at the very first GlobalAlloc of 768 bytes. The error is "not enough storage". How can that be when the TaskMaster shows only 1 GB of memory used with another GB free? Another programmer suggested fragmentation. But why does GlobalRealloc() work over and over and only after freeing the memory and then trying one GlobalAlloc does it fail? I note that I tried this with 5 loops and there was no problem starting up the procedure again after one go-round. Also I'm putting in some tests to see that GlobalFree does indeed work after 40 loops. Is there some way to view what's going on in memory?

Thanks,
Gary

How to lower privileges of a user process started from the system service?

$
0
0
In my local system service I may start a UI process that should run with credentials of the logged on Windows user, but at times, when there's no logged on user, it should be able to start in the Winlogon or "secure desktop" as well.

Thus, I'm using the following construct to prep the user token for it:

Code:

//The following pseudo-code snippet is run from the local system service

HANDLE hSelfToken = NULL;
HANDLE hToken2 = NULL;

::OpenProcessToken(::GetCurrentProcess(), TOKEN_ALL_ACCESS, &hSelfToken);

//Remove most of privileges & create restricted token
::CreateRestrictedToken(hSelfToken,
            DISABLE_MAX_PRIVILEGE | LUA_TOKEN,
            0, NULL,
            0, NULL, 0, NULL,
            &hToken2);

//Set user session ID for the token where the process will run
::SetTokenInformation(hToken2, TokenSessionId, &dwSessionId, sizeof(dwSessionId));

//The 'hToken2' is later used to call CreateProcessAsUser() to start a user UI process

This works great, except that in despite of having pretty much no privileges and no elevation, my UI process that is started with this method still receives too many of the system service's "rights." For instance, it can create a file in "C:\" root folder, or open "HKLM" registry key for writing.

So I'm curious, what else shall I do to lower the child process' privileges?

Problem while converting from 32-bit to 64-bit

$
0
0
I have an MS Office addin using ATL COM. It is working fine, but I want that DLL to run on MS Office 64bit too. For that I went to configuration manager added a new combiler that is X64.

But after changing to X64, these are the errors that I am coming across these errors. Can someone help me with this?

Code:

Error        2        error C4235: nonstandard extension used : '__asm' keyword not supported on this architecture        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        396
Error        3        error C2065: 'fld' : undeclared identifier        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        399
Error        4        error C2146: syntax error : missing ';' before identifier 'dValue'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        399
Error        5        error C2146: syntax error : missing ';' before identifier 'fadd'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        399
Error        6        error C2065: 'fadd' : undeclared identifier        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        399
Error        7        error C2146: syntax error : missing ';' before identifier 'st'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        399
Error        8        error C2065: 'st' : undeclared identifier        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        399
Error        9        error C2146: syntax error : missing ';' before identifier 'fadd'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        400
Error        10        error C3861: 'st': identifier not found        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        399
Error        11        error C2146: syntax error : missing ';' before identifier 'round_to_nearest'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        401
Error        12        error C2146: syntax error : missing ';' before identifier 'fistp'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        401
Error        13        error C2065: 'fistp' : undeclared identifier        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        402
Error        14        error C2146: syntax error : missing ';' before identifier 'i'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        402
Error        15        error C2146: syntax error : missing ';' before identifier 'sar'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        402
Error        16        error C2065: 'sar' : undeclared identifier        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        402
Error        17        error C2146: syntax error : missing ';' before identifier 'i'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        402
Error        18        error C2143: syntax error : missing ';' before '}'        c:\Maverick\Projects\CCPM\SRC\Main_CCPM_11.0.0.7\Utils.cpp        403
Error        21        error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK'        c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h        70
Error        59        error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK'        c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h        70
Error        63        error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK'        c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h        70
Error        66        error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK'        c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h        70
Error        68        error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK'        c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h        70
Error        70        error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK'        c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h        70
Error        72        error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK'        c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h        70

[RESOLVED] Migrating VC++6.0 Application to VC++2015 - AfxClassInit assertion triggered.

$
0
0
I've imported a legacy Visual C++ 6.0 application into Visual Studio 2015 and attempted to compile. The .exe compiles OK but when opening a file within the application, I get debug assertions when certain classes are initialized.

The assertion takes place in ..\..\vctools\vc7libs\ship\atlmfc\src\mfc\afxtls.cpp (Line: 22) which is:
Code:

void CSimpleList::AddHead(void* p)
{
        ASSERT(p != NULL);
        ASSERT(*GetNextPtr(p) == NULL);  /// <-- This assert is triggered.

        *GetNextPtr(p) = m_pHead;
        m_pHead = p;
}


The code is called from AfxInit() which is located in :C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\src\mfc\objcore.cpp (Line: 157)
Code:

void AFXAPI AfxClassInit(CRuntimeClass* pNewClass)
{
        AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
        AfxLockGlobals(CRIT_RUNTIMECLASSLIST);
        pModuleState->m_classList.AddHead(pNewClass);
        AfxUnlockGlobals(CRIT_RUNTIMECLASSLIST);
}

I have a good 100+ classes/objects that initialize fine. I have 12 that trigger this assertion. If I ignore this assertion in debug and continue running the application, I get into trouble with CWnd::SendMessageToDescendants falling into infinite recursion. I suspect that this may be due to AfxClassInit's assertion failure.

What should I be looking at to correct this assertion failure? I know that m_classList.AddHead() expects the GetNextPtr to be NULL, but it's not. What changes in VS2015 would cause this behavior?
Viewing all 3027 articles
Browse latest View live


Latest Images