Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to aspx and was wondering whether it is possible to import a #define constant from c++ to a aspx page.

I am asking because, I am trying to improve readability on this aspx page which is using the constant like a magic number and the constant itself is defined in c++ side.
Posted
Updated 5-Mar-12 11:27am
v2

1 solution

No. This is a preprocessor directive. Technically, such "constant" it does not exist in the compiled executable code. It is not a constant, this is a non-compiled text inserted in the source code in the places where it is used, before compilation. After compilation, it is compiled to immediate constants dispersed in different placed of the code or anything else, which is defined by the details and options of compilation, optimization, etc. You don't have a full control over it and no access from the loaded executable image like DLL.

You can create a static C++ function returning the value you need, export and then P/Invoke that function. For example:
http://stackoverflow.com/questions/3146017/how-do-i-share-a-constant-between-c-sharp-and-c-code[^].

Besides, I would recommend you to avoid using C++ "#define" for the purpose of the definition of values. This practice is majorly obsolete, means poor coding style.

—SA
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900