Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binary creation

Status
Not open for further replies.

Helen1greece

Technical User
Jun 4, 2003
85
GR
I'm trying to find out a way to create a file using its binary text. For example if I have an executable file called "sth.exe", I opened it with MS-DOS Edit and I copied and pasted it in a TextBox in my program. Then I use this source code.

Open "c:\blahblah.exe" For Binary As #1
Put #1,, Text1.Text
Close #1

Is there a way to do something like that? Can anybody give me an example code in order to accomplish that?
 
Am I missing something here? If the output is an identical binary file on disk why not just Filecopy the source exe, renaming it at the same time?

Or is it reading the binary file into a textbox that's the problem?

Paul Bent
Northwind IT Systems
 
An Exe file will likely contain a number of bytes that will not display at all in a textbox. Copying and pasting from Edit will not result in an Exe file.

What are you actually trying to achieve from this?

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
The thing I'm trying to do is to have an exe file in my program and extract it when I need it and run it.Is it possible to do something like that?
 
You should embed the file in the form of binary resource.

Here is how to do this.

1. Start a new project in Visual Basic.
2. Load the VB6 Resource Editor from the Add-In Manager if it not already loaded.
3. Open the Resource Editor and click the Add Custom Resource button.
4. Load the file of your interest (sth.exe). This will create a resource item "CUSTOM"\101.
5. Save the resource file.
6. Now place a command button on your form and place the following code.
___

[tt]Private Sub Command1_Click()
Dim S As String
S = StrConv(LoadResData(101, "CUSTOM"), vbUnicode)
Open "C:\sth.exe" For Binary As #1
Put #1, , S
Close #1
DoEvents
Shell "C:\sth.exe", vbNormalFocus
End Sub[/tt]
___

Run the program, click the button. It will create the file sth.exe and run it.

See also thread222-509531 which discusses the same thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top