I have a function Init()
My app crashes when it returns from the function.
I have isolated the problem to the calling of a pointer. When it calls the pointer, it crashes. When it doesn't call the pointer, it doesn't crash.
Here is the source code for Init() but the more interesting code is the code for the pointer. below
ApplicationName="SerialShieldDemoSample";ApplicationKey="demo";//SerialShieldInitialisation//I'm not sure how to use CStrin. I'mnotsureIcanaccessMFCwithDEVC++//soIconvertedthevaluestostring//SetApplicationInfo(LPTSTR,LPTSTR);m_SSptr->SetApplicationInfo("SerialShieldDemoSample","demo");//m_SSptr->SetApplicationInfo(ApplicationName.GetBuffer(ApplicationName.GetLength()),ApplicationKey.GetBuffer(ApplicationKey.GetLength()));//Loadadefaultkeym_SSptr->SS_DefaultKey("demo","TL-CEA3205Bpb8K5yzQjJHEduwftE6WWHbom7pb5m3C","");m_SSptr->SS_Initialize();//Detectifsystemclockhasbeenmovedback.if(m_SSptr->SS_TrialMode()==99){MessageBox(NULL,"DatemovedBack","Information",MB_OK|MB_ICONINFORMATION|MB_SYSTEMMODAL);}//Verificationiftrialperiodhasbeenexpiredif(m_SSptr->SS_TrialExpired()){m_status="YourTrialLicensehasexpired!";MessageBox(NULL,"YourTrialLicensehasexpired!","Information",MB_OK|MB_ICONINFORMATION|MB_SYSTEMMODAL);printf("YourTrialLicensehasexpired!");//UpdateData(FALSE);}else{intt=m_SSptr->SS_TrialMode();switch(t){//IfSS_TrialMode=1ThenDaysExpirationcase1:m_status=m_SSptr->SS_LicenseInfo();m_status+="daysleft";//MessageBox(NULL,"daysleft","Information",MB_OK|MB_ICONINFORMATION|MB_SYSTEMMODAL);break;//IfSS_TrialMode=2ThenDateExpirationcase2:m_status=m_SSptr->SS_LicenseInfo();m_status+="dateexpires";//MessageBox(NULL,"dateexpires","Information",MB_OK|MB_ICONINFORMATION|MB_SYSTEMMODAL);break;//IfSS_TrialMode=3ThenRunCountExpirationcase3:m_status=m_SSptr->SS_LicenseInfo();m_status+="use(s)remain";//MessageBox(NULL,"use(s)remain","Information",MB_OK|MB_ICONINFORMATION|MB_SYSTEMMODAL);break;//IfSS_TrialMode=4ThenFreeModecase4:m_status=m_SSptr->SS_LicenseInfo();m_status+="TrialFreeMode";//MessageBox(NULL,"TrialFreeMode","Information",MB_OK|MB_ICONINFORMATION|MB_SYSTEMMODAL);break;}}printf(m_status.c_str());printf("Problem#1:Iputsystem('PAUSE')todemonstratethatitcrasheswhenthisinitfunctionreturns\n\n");//Checkifthesoftwareisinunlockedmodeif(m_SSptr->SS_IsUnlocked()){m_status="RegisteredVersion";MessageBox(NULL,"RegisteredVersion","Information",MB_OK|MB_ICONINFORMATION|MB_SYSTEMMODAL);}printf("beforeprintf(m_status.c_str())\n");printf(m_status.c_str());printf("\nafterprintf(m_status.c_str())\n");m_editusername=m_SSptr->SS_GetUserName();m_editkey=m_SSptr->SS_GetUserKey();m_editmachineid=m_SSptr->GetHardwardID();m_editserialid=m_SSptr->SS_GetUserSerialID();//UpdateData(FALSE);
system("PAUSE");
return;
}; [/code]
Below is the code for the pointer
Here's the header [code]
Since the calling of SerialShield* m_SSptr causes the crash on function exit , perhaps I should put the code for SerialShield here. It is attached but I'll put it here as well.
SerialShield.h
Code:
// SerialShield.h: interface for the SerialShield class.
//
// This class is copyright Nic Wilson (C) 2005
// nic@nicwilson.com
//
// It is provided as an example of using SerialShield only.
// Distribution as example source code is permitted for IONWORX.COM
// only. No other distribution is permitted without written consent
// of the author.
//
// No changes to this file or files is permitted
//
// Distribution in compiled binary form is permitted at no cost whatsoever,
// however acknowlegment of use and copyright must be shown in the "about"
// window of the application using this code, and in the documentation.
// such as: "Some code portions Copyright Nic Wilson nic@nicwilson.com"
//
//
// Version History
// V1.00 16th July 2005 - Initial Release
//////////////////////////////////////////////////////////////////////
if !defined(AFX_SERIALSHIELD_H5C4DA086_C149_472E_AF8B_DAC673603DA2INCLUDED_)
bool fail = false;
if (GetHardwardID == NULL)
fail = true;
if (SSUser == NULL)
fail = true;
if (SS_TrialExpired == NULL)
fail = true;
if (SS_RemoveKey == NULL)
fail = true;
if (SS_IsUnlocked == NULL)
fail = true;
if (SS_LicenseInfo == NULL)
fail = true;
if (SS_GetUserName == NULL)
fail = true;
if (SS_GetUserKey == NULL)
fail = true;
if (SS_GetUserSerialID == NULL)
fail = true;
if (SS_R == NULL)
fail = true;
if (SS_TrialMode == NULL)
fail = true;
if (TripleDESEncrypt == NULL)
fail = true;
if (TripleDESDecrypt == NULL)
fail = true;
if (SS_Initialize == NULL)
fail = true;
if (SetApplicationInfo == NULL)
fail = true;
if (Antidebugging == NULL)
fail = true;
if (AntiMonitors == NULL)
fail = true;
if (SS_DefaultKey == NULL)
fail = true;
if (fail)
{
FreeLibrary(m_hSS);
m_hSS = NULL;
return 1;
}
return 0;
}
[/code]
It would be a dream come true if I could figure this thing out.
Is there something inherent in this cod that would allow it to work in Visual C++ with MFC and not on Dev C++ 4992?
When I say crash, i mean that it never returns to main code.
The function Init() does return to the calling function ::SerialShield_Initialize();
But it crashes before returning to the main and it doesn't call any destructores.
Crash is indicated by a message from the Vista operating system which says
SutherlandSample2Console.exe has stopped working.
A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.
Thank very much.
Stephen
PS If anyone wants to see the whole code including the dev project file, please let me know and I'll email it to you.
You have posted a large amount of code that is nonetheless incomplete. You have also not highlighted where this "calling of a pointer" occurs. I assume that you mean calling a function through a pointer? You are making us work too hard!
Init() calls several function through pointers - any particular one!?
Is there are reason for using LoadLibrary/GetProcAddress rather than linking an import library?
Have you tried using the debugger? It is a more robust method of finding the point of failure. Changing the code may be changing the behaviour in ways that lead you to false conclusions.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a function Init()
My app crashes when it returns from the function.
I have isolated the problem to the calling of a pointer. When it calls the pointer, it crashes. When it doesn't call the pointer, it doesn't crash.
Here is the source code for Init() but the more interesting code is the code for the pointer. below
[code]
include "SerialShield_Sample.h"
using namespace std;
SerialShield_Sample::SerialShield_Sample()
{
};
void SerialShield_Sample::SerialShield_Initialize()
{
// TODO: Add extra initialization here
m_SSptr = new SerialShield;
if (m_SSptr == NULL)
{
//MessageBox("Failed to initialize SerialShield class");
MessageBox(NULL, "Failed to initialize SerialShield class", "Information", MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
};
void SerialShield_Sample::Init()
{
printf("Entered SerialShield_Sample::Init() \n\n");
system("PAUSE");
return;
};
[/code]
Below is the code for the pointer
Here's the header
[code]
Since the calling of SerialShield* m_SSptr causes the crash on function exit , perhaps I should put the code for SerialShield here. It is attached but I'll put it here as well.
SerialShield.h
Code:
// SerialShield.h: interface for the SerialShield class.
//
// This class is copyright Nic Wilson (C) 2005
// nic@nicwilson.com
//
// It is provided as an example of using SerialShield only.
// Distribution as example source code is permitted for IONWORX.COM
// only. No other distribution is permitted without written consent
// of the author.
//
// No changes to this file or files is permitted
//
// Distribution in compiled binary form is permitted at no cost whatsoever,
// however acknowlegment of use and copyright must be shown in the "about"
// window of the application using this code, and in the documentation.
// such as: "Some code portions Copyright Nic Wilson nic@nicwilson.com"
//
//
// Version History
// V1.00 16th July 2005 - Initial Release
//////////////////////////////////////////////////////////////////////
if !defined(AFX_SERIALSHIELD_H5C4DA086_C149_472E_AF8B_DAC673603DA2INCLUDED_)
define AFX_SERIALSHIELD_H5C4DA086_C149_472E_AF8B_DAC673603DA2INCLUDED_
if _MSC_VER > 1000
pragma once
endif // _MSC_VER > 1000
include <windows.h>
class SerialShield
{
public:
//All these are public as they need to be accessed from outside the class.
SerialShield();
virtual ~SerialShield();
char (GetHardwardID) (void);
int (SSUser) (char Fullname, char Key, char SerialID);
bool (SS_TrialExpired) (void);
bool (SS_RemoveKey) (void);
bool (SS_IsUnlocked) (void);
char (SS_LicenseInfo) (void);
char (SS_GetUserName) (void);
char (SS_GetUserKey) (void);
char (SS_GetUserSerialID)(void);
int (SS_R) (char Name, char Key);
int (SS_TrialMode) (void);
char (TripleDESEncrypt) (char Text, char Key);
char (TripleDESDecrypt) (char Text, char Key);
void (SS_Initialize) (void);
void (SetApplicationInfo)(char ApplicationName, char SoftKey);
void (Antidebugging) (void);
void (AntiMonitors) (void);
void (SS_DefaultKey) (char Username, char LicenseKey, char* SerialID);
BOOL InitClass();
private:
//This is for class member use only.
HINSTANCE m_hSS;
};
endif // !defined(AFX_SERIALSHIELD_H5C4DA086_C149_472E_AF8B_DAC673603DA2INCLUDED_)
[/code]
Here's the cpp for the pointer
[code]
include "SerialShield.h"
include <windows.h>
include <iostream>
ifdef _DEBUG
undef THIS_FILE
static char THIS_FILE[]=FILE;
define new DEBUG_NEW
endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
SerialShield::SerialShield()
{
printf("\nentered SerialShield() \n");
}
SerialShield::~SerialShield()
{
printf("\nentered ~SerialShield() \n");
}
BOOL SerialShield::InitClass()
{
m_hSS = LoadLibrary("SerialShield.dll");
if (m_hSS == NULL)
return 2;
GetHardwardID = (char()(void)) GetProcAddress( m_hSS, "GetHardwardID");
SSUser = (int ()(char, char, char))GetProcAddress( m_hSS, "SSUser");
SS_TrialExpired = (bool ()(void)) GetProcAddress( m_hSS, "SS_TrialExpired");
SS_RemoveKey = (bool ()(void)) GetProcAddress( m_hSS, "SS_RemoveKey");
SS_IsUnlocked = (bool ()(void)) GetProcAddress( m_hSS, "SS_IsUnlocked");
SS_LicenseInfo = (char()(void)) GetProcAddress( m_hSS, "SS_LicenseInfo");
SS_GetUserName = (char()(void)) GetProcAddress( m_hSS, "SS_GetUserName");
SS_GetUserKey = (char()(void)) GetProcAddress( m_hSS, "SS_GetUserKey");
SS_GetUserSerialID = (char()(void)) GetProcAddress( m_hSS, "SS_GetUserSerialID");
SS_R = (int ()(char, char)) GetProcAddress( m_hSS, "SS_R");
SS_TrialMode = (int ()(void)) GetProcAddress( m_hSS, "SS_TrialMode");
TripleDESEncrypt = (char()(char, char)) GetProcAddress( m_hSS, "TripleDESEncrypt");
TripleDESDecrypt = (char()(char, char)) GetProcAddress( m_hSS, "TripleDESDecrypt");
SS_Initialize = (void ()(void)) GetProcAddress( m_hSS, "SS_Initialize");
SetApplicationInfo = (void ()(char, char)) GetProcAddress( m_hSS, "SetApplicationInfo");
Antidebugging = (void ()(void)) GetProcAddress( m_hSS, "Antidebugging");
AntiMonitors = (void ()(void)) GetProcAddress( m_hSS, "AntiMonitors");
SS_DefaultKey = (void ()(char, char, char*))GetProcAddress( m_hSS, "SS_DefaultKey");
}
[/code]
It would be a dream come true if I could figure this thing out.
Is there something inherent in this cod that would allow it to work in Visual C++ with MFC and not on Dev C++ 4992?
When I say crash, i mean that it never returns to main code.
The function Init() does return to the calling function ::SerialShield_Initialize();
But it crashes before returning to the main and it doesn't call any destructores.
Crash is indicated by a message from the Vista operating system which says
SutherlandSample2Console.exe has stopped working.
A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.
Thank very much.
Stephen
PS If anyone wants to see the whole code including the dev project file, please let me know and I'll email it to you.
Related
Code: code
You have posted a large amount of code that is nonetheless incomplete. You have also not highlighted where this "calling of a pointer" occurs. I assume that you mean calling a function through a pointer? You are making us work too hard!
Init() calls several function through pointers - any particular one!?
Is there are reason for using LoadLibrary/GetProcAddress rather than linking an import library?
Have you tried using the debugger? It is a more robust method of finding the point of failure. Changing the code may be changing the behaviour in ways that lead you to false conclusions.