|
Easily[^]
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
He was joking. He was the guy replying to the thread.
|
|
|
|
|
|
I see Diplomacy is not one of your strong suites!!
|
|
|
|
|
It's called tough love. If you want the help, you need to follow the protocol.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Member 2021022 wrote: I see Diplomacy is not one of your strong suites!!
Really? That's what you are going with? You are the guy that has misused the site and you are going to talk about diplomacy. I see Logic is not one of your strong suites.
|
|
|
|
|
Member 2021022 wrote: I'm porting a WindowsControlLibrary solution from DotNet2003 to 2005
The first thing I'd do is stop using the old syntax...otherwise it's not really a port...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is there porting guide you can direct me to that has examples of the newer syntax?
regards,
-dan
|
|
|
|
|
Member 2021022 wrote: Is there porting guide
No. And if there was one it wouldn't be provided by Microsoft and it wouldn't be located on MSDN and you certainly could not find it using Google. Do you have to have someone wipe your arse for you? Just trying some more of that thar diplormacy thang.
|
|
|
|
|
|
This was extremely useful. Thanks
-dan
|
|
|
|
|
Hello,
I am using C++/CLI and I am trying to use the function SaveFileDialog but when I run the application in Debug mode when the function ShowDialog()is called I get the error:
"An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll
Additional information: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."
And the program quit.
In Release mode the functions SaveFileDialog and OpenFileDialog looks like to work properly.
Can anybody help me wirh this error?
Thank you
|
|
|
|
|
Exception message: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.
[STAThread]
int main()
{
return 0;
}
Eslam Afifi
|
|
|
|
|
And if I have no main?
I have a dll with an exported function.
When you call this function a Windows Form is opened. In this Windows Form I am trying to add a button "Save File" and "Load File" but here is where I get the exception.
Thank you for you answer
|
|
|
|
|
I think you must either make the windows forms STA or run your dll code in a separate STA thread.
var thread = new Thread(() => { new SaveFileDialog().ShowDialog(); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
Eslam Afifi
|
|
|
|
|
I think that should be the way, because the *.exe file that use my dll it is not a managed project, so it hasn´t the property STA.
Thank you,
|
|
|
|
|
You're welcome.
Eslam Afifi
|
|
|
|
|
hi. i have a class like this :
public ref class MyClass : public IDisposable
{
.
.
.
public: MyClass();
private: void Wait();
.
.
.
}
and the cpp file:
MyClass::MyClass()
{
Thread^ t = gcnew Thread(gcnew ThreadStart(&MyClass::Wait));
t->Name = "Event Thread";
t->Start();
}
in compile i got this error :
"error C3350: 'System::Threading::ThreadStart' : a delegate constructor expects 2 argument(s)"
I've looked in msdn and saw a example that exactly used this way for threading but there was no error in compilation.
thank you for help.
sometimes 0 can be 1
|
|
|
|
|
erfi wrote: I've looked in msdn and saw a example that exactly used this way for threading
So why didn't you post a link to the documentation you claim to have seen?
Try looking at the example code in this documentation[^]
|
|
|
|
|
erfi wrote: I've looked in msdn and saw a example that exactly used this way
Exactly?
I have a feeling the Wait() function was static in the example.
Using a non-static function as you've shown won't work because a MyClass
object (instance) is required to make the call to Wait(). You'd have to pass
an instance to the delegate constructor.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi;
I'm finally digging into Reflection and thought, as an exercise, to create an instance of MessageBox and then to modify some of it's (private) properties, such as the font.
Using GetFields() to extract the FieldInfo, all I can get a few items out of it (static values which are, effectively, the return values). As for get Constructor: I get nothing. Creating an instance wants args (for the constructor) which I can't seem to get.
Testing on a very simple home-made method, I can read/write to public/protected/private fields, and the above listing methods (for fields, constructors) works fine.
Any comments and/or steering suggestions for my quest? (code snippets below)
Balboos
Reflection::Assembly ^a = Reflection::Assembly::GetAssembly(MessageBox::typeid);
array<type^>^ typeArray = a->GetTypes();
Type ^TypeToReflect = typeArray[1213];
Object ^n = TypeToReflect->InvokeMember("IDOK", BindingFlags::GetField | BindingFlags::Public | BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::Static, nullptr, TypeToReflect, nullptr );
array<system::reflection::fieldinfo xmlns:system="#unknown"> ^fields = TypeToReflect->GetFields(
BindingFlags::Public | BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::Static);
array<system::reflection::constructorinfo> ^Members = TypeToReflect->GetConstructors();
</system::reflection::constructorinfo></system::reflection::fieldinfo>
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"How do you find out if you're unwanted if everyone you try to ask tells you to stop bothering them and just go away?" - Balboos HaGadol
"It's a sad state of affairs, indeed, when you start reading my tag lines for some sort of enlightenment. Sadder still, if that's where you need to find it." - Balboos HaGadol
|
|
|
|
|
MessageBox is a static class, there isn't any constructor, there is just one useful method and all it does is wrap the native MessageBox function. It probably is the worst class for getting acquainted with reflection!
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Tuesday, March 31, 2009 12:01 PM
|
|
|
|
|
Thanks - I can't stop spinning those wheels (an exhausting job, this running in place).
Ok - So it's a bad choice.
Still, why can't I get to any of it's internal info (particularly members), aside from the enum of return values, via reflection? I suppose when I start to understand what I'm doing, that will become clear. The link to the native version brings to mind MessageBoxA (of what seems so long ago).
I'll certainly choose another target that can be interesting. The static classes, like MessageBox, seemed to hold so much promise for tweaking fun.
Once again, thanks.
Balboos
|
|
|
|
|
I have a Windows service written in C#, that needs to load a C++ SDK. I have written CLI classes, that acts as a bridge. The problem is that my CLI code fails at the point where it makes call to the C++ SDK. I am not getting any error message also. It just hangs. If I try the same from Win Forms application, I did not see any problem. For me it looks like there is issue only when using Windows service. Is it possible to consume CLI\C++ dll's inside windows serive?
Please clarify me on this.. Any link related to the problem will be much helpful.
|
|
|
|
|
BicycleTheif wrote: Is it possible to consume CLI\C++ dll's inside windows serive?
Yes.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|