|
I need to call a managed C++ dll from our native C++ code. To manage this i followed the tutorial in http://support.microsoft.com/kb/828736 "How to call a managed DLL from native Visual C++ code in Visual Studio.NET or in Visual Studio 2005."
However I'm using VS2008 and the article is using a managed C# dll.
Were the article says:
Replace the following lines of code in the AssemblyInfo.cs file
[assembly: ComVisible(false)]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
with the following.
[assembly: ComVisible(true)]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("..\\..\\MyKeyFile.SNK")]
I added the SNK file to the projects property "linker->Advanced->Key File" and changed [assembly: ComVisible(false)] in the AssemblyInfo.cpp file.
Now when I build my solution I get following errors in the native code:
error C2787: 'WNXal::NeXus' : no GUID has been associated with this object
error C2079: 'pINeXus' uses undefined struct 'WNXal::INeXus'
Code snippit:
--------------
#import "../Lib/NeXus/References/WNXal.tlb" raw_interfaces_only
using namespace WNXal;
HRESULT hr = CoInitialize(NULL);
INeXus pINeXus(__uuidof(WNXal::NeXus));
long lResult = 0;
e = pINeXus->Initialize();
CoUninitialize();
Benny
|
|
|
|
|
Stray Bullet wrote: I need to call a managed C++ dll from our native C++ code.
Alternatively you can make a mixed mode project to solve that problem without the need to expose the managed classes using COM
[Native module] calls --> [Mixed Mode module] calls --> [Managed module]
no COM.
led mike
|
|
|
|
|
I have designed a Winform Form, lets say Form1.h. I can switch to its Form designer and drop components etc. Now, if i insert this Form1.h in a different solution/project, i can compile, call the Form, but i cannot switch to the form designer. It's like a plain .h file. How can i make VS2008 understand that this is a form, so that i can edit it visually?
I'm using VS2008 C++/CLR.
Thanks
|
|
|
|
|
uus831 wrote: Now, if i insert this Form1.h in a different solution/project, i can compile, call the Form, but i cannot switch to the form designer.
What if you copy and add the Form1.resx file to the new project as well?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi, i tried that too, but its just the same. I cant switch to form designer.
|
|
|
|
|
I ran into a similar problem not long ago (using VS2005 Pro). Here's how I solved it
1. In the project you want a copy of the Form1, simply add a new Form object. Be sure to call it Form1 was well (or whatever you called it in your original project).
2. Delete the .h and .cpp files for the form you just created. Leave the .resx file alone.
3. Copy Form1.h and Form1.cpp from your original project to your new project and compile. Be sure to rename them to whatever you called the form you just deleted. Since your copied form is now the same name, it should work just fine.
I'm not certain if this is exactly what I did, but I have it documented at work. I can check on it Monday.
Dybs
|
|
|
|
|
Thanks!!! It works! I have tried, and it works great. Except, that you need to rename the namespace so that it is the same in the new project.
Great tip!
Thanks again.
|
|
|
|
|
Oh yeah, kinda forgot the namespace thing No problem, glad to help.
Dybs
|
|
|
|
|
Hi,
I'm trying to call CreateThread() from windows.h using the below code:
The problem argument seems to be the emphasised one...
<br />
unsigned long i;<br />
<br />
CreateThread(NULL, 0, LiftThread, (void *)i, 0, &id);<br />
Im getting the error:
Error 5 error C2440: 'function' : cannot convert from 'unsigned long (__cdecl *)(void *)' to 'LPTHREAD_START_ROUTINE'
Does anyone know how I could fix this?
Cheers,
|
|
|
|
|
Your thread procedure needs to be defined as follows:
DWORD WINAPI LiftThread(LPVOID lpParameter);
Is that how you defined it?
Also, non-C++/CLI questions should be posted on the Visual C++/MFC board
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
Ok i'll give that a try.
Mark Salsbery wrote: DWORD WINAPI LiftThread(LPVOID lpParameter);
Tracing back the define statements I believe the function is defined like that, except there is no DWORD. I'll try it with the DWORD when I get home.
Mark Salsbery wrote> Also, non-C++/CLI questions should be posted on the Visual C++/MFC board
Whoops, prolly should have searched MFC and CLI before posting :P.
Thanks,
|
|
|
|
|
I am using Visual c++ NET 2005
In each forms I write down the path of Icon property.
When I load the program, the Icon appear on the left corner of Title bar but in left side of menu bar appears the default icon. I do no where to change this . I need that appears in menu bar a new icon instead of the default.
I need your help.
|
|
|
|
|
This isn't really a C++/CLI question.
Although you may get a solution here, you may want to try asking
this on the Windows Forms[^] board.
I'm not even sure what icon you're referring to
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
We are doing interop between MFC and a custom C# dialog control with multiple sub controls that we are hosting in a CDialog with the DDX_MangedControl.
Everything works as expected until the user enters a TextBox Field with UseSystemPasswordChar=true, with the caps lock key turned on.
At which time it displays a ballon message informing the user that the caps lock key is on.
When the user turns the caps lock key off the whole control surface with the exception of the TextBox field it self disappears.
If you let the ballon tip expire normally then the portion of the tip that was under the ballon tip does repaint.
Any suggestions on how to fix this?
Thanks!
|
|
|
|
|
What sort of things have you tried so far?
led mike
|
|
|
|
|
Well after a bit of seaching I found a example of code that supresses the tooltip popup with EM_SHOWBALLOONTIP which I then adapted as a bute force solution that works with a horible blink of the entire control.
I did this by adding a timer to the base control and starting it from the text field to refresh the entire control.
tb_password.Tag = (object)timer1;<br />
<br />
<br />
public class PasswordControl : TextBox<br />
{<br />
private const int EM_HIDEBALLOONTIP = 0x1504;<br />
protected override void WndProc(ref Message m)<br />
{<br />
if (m.Msg == EM_HIDEBALLOONTIP)<br />
{<br />
System.Windows.Forms.Timer timer =<br />
(System.Windows.Forms.Timer) this.Tag;<br />
timer.Start();<br />
}<br />
base.WndProc(ref m);<br />
}<br />
}<br />
<br />
<br />
private void timer1_Tick(object sender, EventArgs e)<br />
{<br />
timer1.Stop();<br />
this.Refresh();<br />
}
Does anyone have a better solution?
Thanks
|
|
|
|
|
fredsparkle wrote: Does anyone have a better solution?
Well I was going to suggest something until I saw you voted down my post.
led mike
|
|
|
|
|
Yep, you are not the first victim of the modern voting system.
Best way to avoid this (or reduce its probability) is to modify
the message type away from "answer" when the only thing you (rightfully) do
is ask some questions, since those questions are strictly not an "helpful answer"
to the OP.
|
|
|
|
|
Luc Pattyn wrote: Best way to avoid this (or reduce its probability) is to modify
the message type away from "answer" when the only thing you (rightfully) do
is ask some questions
Perhaps, but that doesn't stop the 'Bad Question' voting mechanism which just equates to a '1' correct?
Also, the default message type isn't "Answer" anyway, it's "General Comment".
led mike
|
|
|
|
|
Hi led mike
The question was did your solve my problem and sorry the answer to was no, it only gave me two choices; so thats what I clicked.
|
|
|
|
|
fredsparkle wrote: The question was did your solve my problem and sorry the answer to was no, it only gave me two choices; so thats what I clicked.
proving my point exactly.
|
|
|
|
|
Thanks fred. May I suggest that until everyone gets the hang of this new voting mechanism you only vote Yes otherwise don't vote at all.
led mike
|
|
|
|
|
led mike wrote: that doesn't stop the 'Bad Question' voting mechanism
Well, if you ask bad questions (whatever that is), then 1 is what you deserve.
led mike wrote: the default message type isn't "Answer" anyway, it's "General Comment".
I don't think so. The first-level reply to a question is an answer by default (like this one).
|
|
|
|
|
Ok got rid of the annoying flash. The problem with the timer approach is that its minimum granularity is 1/10 of a second.
The final solution is to define a delegate which under the covers (way deep) does a Post Message, so the refresh operation happens after it hides everything when the ballon tip goes away.
In the main custom control:
public delegate void InvokeDelegate();
tb_password.Tag = (object)new InvokeDelegate(Refresh);
Our extended textbox:
public class PasswordControl : TextBox<br />
{<br />
private const int EM_HIDEBALLOONTIP = 0x1504;<br />
protected override void WndProc(ref Message m)<br />
{<br />
if (m.Msg == EM_HIDEBALLOONTIP)<br />
{<br />
Delegate del = (Delegate)this.Tag;<br />
this.BeginInvoke(del);<br />
}<br />
base.WndProc(ref m);<br />
}<br />
}<br />
Theory of operation:
1. Create a delegate for the refresh operation for the master custom control container.
2. Assign it as a tag to the textbox that is used as a password field.
3. Extend the textbox class to monitor for the hide ballon tip messages.
4. When the extended textbox class sees that there is a closing ballon tip it instructs the master control to refresh it self via the previously created delegate.
|
|
|
|
|
Luc Pattyn wrote: I don't think so. The first-level reply to a question is an answer by default (like this one).
I see you are correct. Although at times the "General Comment" is the default like in this current reply. Ok I guess the default changes based on the type of the post you are replying to, I never knew that. Thanks for pointing all this out to me, although I imagine it will take me some time to start remembering to select a type, I never used to worry about it aside from occasional use of the joke type.
led mike
|
|
|
|