Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: BCB XE7 64-bit compiler: Access to Application global from a package


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Jan 19, 2015 4:18 AM Last Post By: Hans-Peter Scha...
Marko Majic

Posts: 14
Registered: 1/20/03
BCB XE7 64-bit compiler: Access to Application global from a package  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 23, 2014 11:54 AM
I am trying to convert a fairly straight-forward BPL package to XE7 (originally in XE2) and create both 32-bit and 64-bit version (original only 32-bit). 32-bit version compiles fine and works the same way as it did in XE2. 64-bit package also compiles fine (after some changes to how exported global vars are declared) but it crashes in attempting to access Application global variable (e.g. calling Application->MessageBox() or accessing Application->Title from the package results in $C00...05 access violation - while it works fine when the package and the test application are compiled as a 32-bit target).

Has the Application global been deprecated for 64-bit VCL (compiler is not complaining about it and it still works fine even in 64-bit when accessed from the application itself - just not from the package)? Is there any initialization that need to be explicitly done for VCL to initialize globals in the 64-bit target?

I also created an even simpler package that only has one single export:
Header file:
//---------------------------------------------------------------------------
#ifndef PackageUnit1H
#define PackageUnit1H
//---------------------------------------------------------------------------
int PACKAGE TestMe();
#endif
 
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
 
Source file:
 
#include "PackageUnit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
 
int PACKAGE TestMe()
{
	Application->MessageBox(L"Test Me", L"From Package", MB_OK);
}


Along with an equally simplistic application that calls TestMe() in response to a button click and it also works fine when compiled 32-bit and crashes the same way ($C00...05 access violation) when compiled to a 64-bit target.

So... Anyone knows if there are any extra initialization steps that need to be taken for 64-bit VCL packages?

Thanks...

Marko

Edited by: Marko Majic on Dec 23, 2014 11:55 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: BCB XE7 64-bit compiler: Access to Application global from a package[Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 23, 2014 12:00 PM   in response to: Marko Majic in response to: Marko Majic
Marko wrote:

Has the Application global been deprecated for 64-bit VCL

No, of course not.

Do you have Runtime Packages enabled in both the BPL and EXE? If not, then
they will not be sharing a common Application object.

--
Remy Lebeau (TeamB)
Marko Majic

Posts: 14
Registered: 1/20/03
Re: BCB XE7 64-bit compiler: Access to Application global from a package[Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 23, 2014 12:14 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Do you have Runtime Packages enabled in both the BPL and EXE? If not, then
they will not be sharing a common Application object.

Yes, of course... Link with runtime packages has been enabled for the EXE. As for the BPL - I wasn't aware that you can even link it without runtime packages?

Marko
Hans-Peter Scha...

Posts: 1
Registered: 1/15/04
Re: BCB XE7 64-bit compiler: Access to Application global from a package[Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 19, 2015 4:18 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Marko wrote:

Has the Application global been deprecated for 64-bit VCL

No, of course not.

Do you have Runtime Packages enabled in both the BPL and EXE? If not, then
they will not be sharing a common Application object.

--
Remy Lebeau (TeamB)

I got the same problem.

1. Created a new 64bit Package with just one edit control (.bpi + .bpl)
2. Accessed the "Application" pointer in the constructor of the new control (e.g. HWND hWnd = Application->Handle;)
3. Placed this control in a new VCL application (Runtime packages)
4. The application crashes as soon as the "Application" pointer is used.

Peter
Marko Majic

Posts: 14
Registered: 1/20/03
Re: BCB XE7 64-bit compiler: Access to Application global from a package  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 23, 2014 1:37 PM   in response to: Marko Majic in response to: Marko Majic
This may (or may not) be partly related to the problem with the Application global variable but can anyone tell me what is the proper way to export your global variables from your package with a 64-bit compiler?

With many of my low-level 32-bit packages, I have a class defined in the header file like so:

//---------------------------------------------------------------------------
#ifndef tmyunitH
#define tmyunitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <string>
#include <vector>
using namespace std;
 
class PACKAGE TMyClass
{
public:
	TMyClass();
...
};
 
extern PACKAGE TMyClass my_var;
 
#endif


With the corresponding implementations and definitions in the source file:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma package(smart_init)
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <windows.h>
 
TMyClass my_var;
 
TMyClass::TMyClass()
{
}


This would create the class code in the package as well as the exported global variable of the type. Using this package in the EXE or from other packages worked fine. If either the EXE or another package referred to my_var - it was all referencing the same global variable created by the package.

This does not seem to work quite the same way with a 64-bit compiler - the main difference being that the 64-bit code does NOT export the global variable. I tried changing the declaration and definition in a few ways without success.

Is there any documentation or guidelines as to how this is supposed to work with the 64-bit compiler?

Marko
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: BCB XE7 64-bit compiler: Access to Application global from apackage  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 23, 2014 3:20 PM   in response to: Marko Majic in response to: Marko Majic
Marko wrote:

This does not seem to work quite the same way with a 64-bit compiler -
the main difference being that the 64-bit code does NOT export the
global variable. I tried changing the declaration and definition in a
few ways without success.

Does this apply to your situation?

Differences between Win32 and Win64 packages
http://docwiki.embarcadero.com/RADStudio/XE7/en/C%2B%2BBuilder_64-bit_Windows_Differences#Differences_between_Win32_and_Win64_packages

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02