|
Google for "Win32 Disassembler".
|
|
|
|
|
I don't know where this error message is coming from. It keeps saying that classes and methods aren't where they're supposed to be. Two examples of code that are causing the erros:
this->Icon = (__try_cast<System::Drawing::Icon * >(resources->GetObject(S"icon32.co")));<br />
<br />
MessageBox::Show(S"Error loading Wompi.", S"Loading Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
The first example throws the error C2039: 'GetObjectA': is not a member of 'System::Resources::ResourceManager'
The second throws another C2039: 'MessageBoxA': is not a member etc...
Where is that 'A' coming from? Any help would be greatly appreciated. Thank you.
Sleep is for the WEAK!
|
|
|
|
|
A lot of functions that take strings have two functions, one that ends in A and one that ends in W ( for ASCII and Wide ). Then you have a macro defined for MessageBox, which defines itself according to the type of project, so that it uses the default type of string in use. This macro is what's causing you trouble. I've had the same hassle recently, I tried to write a class method of 'DrawString'. I changed it to 'WriteString' in the end. Writing code to kill the macro may be a solution when it happens with framework methods.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Wow, is that ever a pain in the ass. I don't really know enough about macros to kill it in this case. Where is it getting the default type of string? From the variable I'm passing maybe? Is there maybe something else I've loaded or option I've broken? I've been having problems with strings in general all of a sudden in this program.
Sleep is for the WEAK!
|
|
|
|
|
Ok, I fixed it by using #undef's on GetObject and MessageBox. But now GetObject won't grab the icon file I need it to grab.
this->Icon = (__try_cast<System::Drawing::Icon * >(resources->GetObject(S"app.ico")));
I tried grabbing it by file using System::Drawing::Image::FromFile and then casting it into an icon, but that didn't work either. Does anyone know a way to grab the .ico from the file? I'll just keep it in the same folder as the .exe. Thanks in advance.
Sleep is for the WEAK!
|
|
|
|
|
If you hover your mouse over GetObject befure you UNDEF it, you can right click and go to the macro definition. Copy that and write your own, but rename it. Then you can use that.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Do something like this :-
#pragma push_macro("MessageBox")
#undef MessageBox
MessageBox::Show(...);
#pragma pop_macro("MessageBox")
Nish
|
|
|
|
|
How can i make a variable volatile in c or c++ without actually qualifying it using the keyword volatile..
:->
|
|
|
|
|
i think (but not sure) that there may be a compiler command-line parameter for such an optimisation, but i doubt if any command exist that you could limit the compiler optimisation to only one variable...
to sum up, this is almost sure that it is not possible...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Ok... but the problem is that i was asked this question in an interview... and the interviewer was quite sure its possible....
but i have no idea how.
|
|
|
|
|
Pegasus Kiddo wrote: #define vfor volatile
vfor variable;
#define vfor volatile
vfor variable;
I think this will do
regards
|
|
|
|
|
but that DOES use the volatile keyword, which Pegasus Kiddo don't want to...
hidding a word with another doesn't mean it is not used anymore... the compiler will see volatile as if it would have been written by the developer.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
ok, let's sum up.
what volatile is suposed to do ?
it is there to tell the compiler not to perform optimisations on the code it will generate because the variable marked as volatile may be modified from outside the process.
from the MSDN :
"Objects declared as volatile are not used in optimizations because their value can change at any time. The system always reads the current value of a volatile object at the point it is requested, even if the previous instruction asked for a value from the same object. Also, the value of the object is written immediately on assignment.
One use of the volatile qualifier is to provide access to memory locations used by asynchronous processes such as interrupt handlers."
do you see any point in the C++ language that allow you to perform such an action rounding over the volatile keyword ? no.
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 8:09 Tuesday 29th November, 2005
|
|
|
|
|
toxcct wrote: do you see any point in the C++ language that allow you to perform such an action rounding over the volatile keyword ? no.
Actually yes. When you use a thread and you're sharing a variable, for instance.
class A
{
static bool bFlag;
void MethodA()
{
AfxBeginThread(&methodB,...);
Thread.Sleep(1000);
bFlag = false;
}
static UINT MethodB(LPVOID param)
{
while (!bflag)
{
...
}
}
}
might not work as expected, because the compiler can optimize away the while loop condition. The volatile keyword prevents that from happening.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I suppose if you pass a variable by adress/reference to another function (outside the current compilation unit/module), the compiler is forced not to assume any optimization techniques regarding the variables value... Just an idea.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
Hi,
I have an MFC application which talks to a DLL which talks to driver to send/receive data from a device.
When I send a command using the dllexport functions, I need the dllexport function to wait for a flag which will be set by the WndProc-OnDeviceChange function and dllexport funtion should return with some data which will be available after the flag is set.
I used a while loop in the dllexport functions checking for the flag and was setting the flag in WndProc assuming that the dllexport function and WndProc runs on different threads.
But this is not working. The application hangs.
Can you please suggest me another mechanism/logic to do this ?
- KK
|
|
|
|
|
When different threads r running and accessing a flag may cause collision.
You can use interlockedincrement or semaphore synchronization.
regards
|
|
|
|
|
Can you suggest any article where I can get a quick understanding of "interlockedincrement or semaphore synchronization" ?
- KK
|
|
|
|
|
Sleep is for the WEAK!!! Sorry too much caffeine.
Anyway, shout of thanks to Mr. Sivakumar for his help.
My new problem is grabbing the class out of the DLL. The assembly loads fine, but it doesn't seem to be finding the class inside the DLL. Here's the code:
a = Assembly::Load("LeetTrans");<br />
t = a->GetType("LeetTrans.LeetTrans");<br />
<br />
#pragma once<br />
#include "Wompi.h"<br />
#include "stdafx.h"<br />
#using <mscorlib.dll><br />
using namespace System;<br />
namespace LeetTrans<br />
{<br />
public __gc class LeetTrans : public Wompi<br />
{...}; <br />
}
I am watching the debugger and GetType never grabs the class. Do I need to put the class in the .DEF file somehow? A compiler option or property off maybe? I'm having trouble in general with the namespace and getting it to recognize the methods if I put them in a .cpp file so I feel like that may be where my problem is, but I can't figure it out. Any help is greatly appreciated. This site and everyone on it kicks ass. I just don't know why .NET hates me.
I am... the Warcow.
|
|
|
|
|
|
I figured it out. I was getting a null pointer exception on the Type. The namespace and class have to be in a .cpp file. It doesn't like headers for whatever reason. One of the readers of your article came across the same problem. It didn't hurt my code any to shift it all over to the one .cpp so I did. Thanks for all you're help though. The LoadLibrary/GetProcAddress method I was using would have taken me another 5 years to finish. It all runs, and runs like a dream. Speaking of dreams....
Sleep is for the WEAK!
|
|
|
|
|
I want to know, what are the typical differences between C++ Classes and Structures. All of us knows that, there is a main difference between the default visibility of parameters/methods [Private and Public]. Apart from this, are there any differences? Like memory allocations etc..
|
|
|
|
|
this question has been asked last week on the C++ forum (as it is a pure C++ question, it has nothing to do on the Managed C++ forum).
consider in basics that in C++, a struct is a class which default members are public...
see here[^]...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Ok, my last post was just too big. I'll try to shorten it here. I'm trying to load DLLs dynamically using the LoadLibrary/GetProcAddress method. What I want to do is call a function in the DLL that creates an instance of the class I need. However I am getting an error:
System.Runtime.InteropServices.MarshalDirectiveException in Unknown Module
PInvoke Restriction: can not return variants
I'm not sure what is wrong, but it seems to be a problem with the variable.
The function looks like this:
Object __gc * __cdecl Build()<br />
{<br />
LeetTrans * a = new LeetTrans();<br />
return a;<br />
}
The head of LeetTrans looks like this:
public __gc class LeetTrans : public Wompi
And the head of Wompi looks like this:
public __gc class Wompi : public System::Windows::Forms::GroupBox
Now for the loader code,
typedef Object __gc * (__cdecl *Builder)();<br />
Builder build;<br />
FARPROC holder;<br />
Object __gc * wompi;
Here's where we cast the function and simply call the function to Wompi:
build = (Object __gc*(*)()) holder;<br />
wompi = build();
This is where our error occurs. So I'm guessing I'm losing the variable somewhere along the way, but I don't know where to begin. Any help would be greatly appreciated. Thank you.
-- modified at 18:23 Monday 28th November, 2005
|
|
|
|
|
Bobamagoo wrote: I'm trying to load DLLs dynamically using the LoadLibrary/GetProcAddress method.
If these are managed types, why don't you use reflection, which is the right way to do this?
|
|
|
|