Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
So my questions is:

How do i add an exe as reference?

More explanation:
Im having a doubt of how to add an exe as reference using Visual Studio 2010;
Here is a part of what im actually trying to do:

To embed it into your own app, simply reference the EXE as if it were a DLL from your app in Visual Studio.
It should show up in the Toolbox Window in Visual Studio.


I dont really know if im adding it the correct way.

Im trying to do it as explained in this post:
A Windows Forms based text editor with HTML output[^]
But its not working.

i´m asking help because im new to VS 2010.

Do you know the answer?
Posted
Updated 1-Dec-13 10:21am
v2

For the case that you have referenced, the instructions are wrong.

A little info first. That executable was compiled against the .Net 4.0 Full Framework. You will need to use VS2010 or higher and set your application to use the full framework and not the client.

You can add the control for the executable to your toolbox by right clicking on the toolbox and selecting "choose items" and then clictthe "Browse" button under the ".Net Tab". Then navigate to where you stored the file and selct it. It should then show up in your Toolbox with the name "editor". I suggest that you right click on the Toolbox-General tab or add a new tab so that you can locate the add control more easily.
 
Share this answer
 
Comments
Zero The Warrior 1-Dec-13 18:10pm    
That´s it! So thats the right way.
Still not working, but answered this question.
E-mail me if you can help me with the error i posted at solution 2 comment.

Thanks a lot!
TnTinMn 1-Dec-13 19:03pm    
The original code handles conversions between System.Drawing.Color and HTMLColor incorrectly in a few places. You would need to either contact the author to correct it or download the source code and edit it yourself. I found two places where the code is incorrect; the first is the BodyBackgroundColor property and the second is the SetBackgroundColor method. There may be others. The corrected code is as follows:

public Color BodyBackgroundColor
{
get
{
if (doc.body != null && doc.body.style != null && doc.body.style.backgroundColor != null)
return ColorTranslator.FromHtml(doc.body.style.backgroundColor.ToString()); // ConvertToColor(doc.body.style.backgroundColor.ToString());
return Color.White;
}
set
{
if (ReadyState == ReadyState.Complete)
{
if (doc.body != null && doc.body.style != null)
{
//string colorstr =
// string.Format("#{0:X2}{1:X2}{2:X2}", value.R, value.G, value.B);
doc.body.style.backgroundColor = ColorTranslator.ToHtml(value); //colorstr;
}
}
}
}




private void SetBackgroundColor(Color value)
{
if (webBrowser1.Document != null &&
webBrowser1.Document.Body != null)
webBrowser1.Document.Body.Style =
string.Format("background-color: {0}", ColorTranslator.ToHtml(value)); // value.Name
}

Zero The Warrior 2-Dec-13 5:47am    
The error was truly fixed. Thanks.

Now one or another error appear:
The type or namespace name 'LiveSwitch' could not be found (are you missing a using directive or an assembly reference?)

If i turn on the "Embed Interop type" = True
then this happen:

Cannot embed interop types from assembly 'c:\LiveSwitch.TextControl.exe' because it is missing either the 'ImportedFromTypeLibAttribute' attribute or the 'PrimaryInteropAssemblyAttribute' attribute

Thanks for the help, i will repass the fixes to the author with your name. I will continue trying to make it work.
Zero The Warrior 2-Dec-13 9:20am    
Got the solution changing the target framework to .NET Framework 4.0
This is how i did this:
-Right click on project name
-Properties
-Apllication tab
-Target framework: .NET framework 4.0

This worked for me.

Any furthers errors are simple to solve.
Thanks a lot everybody! Mainly TnTinMn!
First embedding vs. referencing.

If you want to be able to use classes in the EXE as if it were a DLL, then you want to reference it.

If you want to include the EXE as a resource inside your application, perhaps so you can redistribute it on the client, then you want to embed it.

I think you mean reference.

The instructions that you are following is the correct way to reference a managed executable. A managed executable[^] is one that was created using a .NET language[^] and compiled to CIL[^].

I have a feeling that you are trying to reference an EXE that is not managed code. This is possible, but is very different, and uses native interop.
 
Share this answer
 
v3
Comments
Zero The Warrior 1-Dec-13 17:38pm    
I just want to get the text editor and use it as a component in the visual studio toolbox.
The "text editor" is in the link i posted.

I think i want to embed it.
Yvan Rodrigues 1-Dec-13 17:41pm    
Once you have referenced it, try adding it to the toolbox manually. Right click in the toolbox, then Add, and find the component in the list and check it.
Referencing the executable in the project's references is one thing (that you have to do). If you did not change the default layout, it has to be done on the right side, in the Solution Explorer.

If you want to use some controls that are defined in this executable, then you have to add these controls to the toolbox, which is on the left side:
Right click inside the Tool Box, and choose 'Choose elements...'; then go and search for the controls you want to add/use.

Hope this helps.
 
Share this answer
 
Comments
Zero The Warrior 1-Dec-13 18:04pm    
But when i add a reference at the right side, should the control (in that case the text editor) apear on tool box elements list? (this when i click 'choose elements').

Because i´m adding as reference at right side.
Choosing the 'Browse Tab'
and looking for the archive .exe

But when i add the reference, nothing apears on toolbox.
I tryed to click on 'Choose elements' and browse from there too.
The control apeared, but its causing some errors.

ERROR:
Code generator for property 'BodyBackgroundColor' failed. Error was:
"Property acessor 'BodyBackgroundColor'on object 'editor1' threw the following exception: 'Input string was not in a correct format".

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