Unconventional implementation of VB embedding files

zhaozj2021-02-16  48

Embedding files in the file, generally achieved by resource files, as for specific implementation steps, I don't want me to be, there are many such articles on the Internet, unclear friends can search themselves. However, in some cases, if you can't solve the problem with the resource file, you have to go back, so you have to achieve so-called green software (here I want to explain here, this article does not involve any advanced skill, so you have not seen it. I will not feel sad). In fact, everyone knows that the VB program is running requires support for VB running libraries, so it is almost impossible to use VB to do green software. Fortunately, some versions of Window Installing the VB runtime support file, providing opportunities for impossible. However, once we use the third party control or in other similar situations, this implementation of green software may be slightly slight, what should I do? If you don't have green software with a resource file, then it means that we must give up this tempting idea? Don't worry, you will know how you should do it. :)

My answer is in the form of code, embedding files into our VB program, below I have known how to register with API functions (of course, I can call Regsvr32 in the program), know how to read and write files And registry, these issues, and this issue is closely related, you need to know if you don't know, you can get the answer from the search engine.

The specific implementation step is to determine if the key value in the registry is loaded during the program load, and if it is the first run, the required path is generated and written to the data. Then, call the API function registration control, and write the registry, the tag has been running.

The approximate programs written in writing are as follows:

DIM BUFF () AS BYTE Next to write the file content to the file content to array the statement Open File name for binary as # 1 PUT # 1, Buff Close # 1

Seeing this, some friends want to be pleasing to me, I will be angry to me: I don't know how you said, how is the key to assign a value, do you want to view file data with a 16-encycloped editor, Do you assign a value? At this time, I will answer: Yes, but this process can be implemented, see the following code:

Private Sub writetext (ByVal FileName As String, ByVal ByteArrayName As String, ByVal TxtFile As String) Dim i As Long i = FileLen (FileName) Dim arr () As Byte ReDim arr (i - 1) Open FileName For Binary As # 1 Get # 1,, arr close # 1 DIM TEMPS AS STRING OPEN TXTFILE for OUTPUT AS # 1 Print # 1, "Redim" ByteaRrayName "(" CSTR (i - 1) "" for i = 0 to Ubound Arr) Temps = ByteArrayName "(" CSTR (i) ") =" CSTR (Arr (i)) Print # 1, Temps next close # 1 'msgbox "haha" End Sub This piece of code is automatically Write the code you need to manually entered into a text file, your remaining job is, call this code, manually open the file you just generated, select all the words, copy, and paste into VB, you need to manually write code local. The parameter filename is the file name of the file you need to embed, ByteArRayName is the number of group names used in your program (if you use my paragraph to make you angry code, you will pass "buff"), txtfile is the text to be generated. File name of the file. If you want to embed the C: / TOCX embedder on your disk, you can call: WriteText "C: / Test.ocx", "BUFF", " D: /MC/mc/buff.txt ", then open the file D: /MC/mc/buff.txt, proceed, all select, copy, paste.

Have to say, although you can release files in the program, automatically register, but if you use the third party control, your program is still not working properly, that is, you You must use the code to add a control on the form (using controls.add, you need to know the proGID, if you are ActiveX DLL, if it is an ActiveX DLL, you can use CreateObject to bind it). However, in this case, you have to resolve the response problem of the control event, then you can only solve the problem with VBCONTROLEXTENDER, detail reference: How to dynamically add control items? Http://vbboshi.myrice.com/preblem/41-60/pr52.htm#259

转载请注明原文地址:https://www.9cbs.com/read-23165.html

New Post(0)