hi.
i hv this code and i can read unicode names files but my problem is about get content data and then save unicode names with same content data.
Code:Option Explicit Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameW" (pOpenfilename As OPENFILENAME) As Long Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameW" (ByRef pOpenfilename As OPENFILENAME) As Long Private Type OPENFILENAME lStructSize As Long hWndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type Dim sString As String Dim tmpsave As String Private opFile As OPENFILENAME Private FSO As FileSystemObject Private Function ShowOpenUnicode() As String With opFile .flags = &H2 Or &H4 .hInstance = App.hInstance .hWndOwner = Me.hWnd .lpstrFilter = StrConv(("all Files" & Chr(0) & "*.*" & Chr(0) & Chr(0)), vbUnicode) .lpstrTitle = StrConv("Open File", vbUnicode) .lpstrFile = StrConv(String(256, Chr(0)), vbUnicode) .nMaxFile = 512 .lStructSize = Len(opFile) End With Call GetOpenFileName(opFile) ShowOpenUnicode = opFile.lpstrFile End Function Private Function ShowSaveUnicode() As String With opFile .flags = &H2 Or &H4 .hInstance = App.hInstance .hWndOwner = Me.hWnd .lpstrFilter = StrConv(("all files" & Chr(0) & "*.*" & Chr(0) & Chr(0)), vbUnicode) .lpstrTitle = StrConv("Save File", vbUnicode) .nMaxFile = 512 .lpstrFile = sString & String(512 - Len(sString), Chr(0)) .lStructSize = Len(opFile) End With Call GetSaveFileName(opFile) ShowSaveUnicode = opFile.lpstrFile End Function Private Function ConvertFileName(sToConvert) As String Dim bFileName() As Byte Dim lRet As Long Dim sBuf As String 'Get rid of the trailing Null characters sToConvert = Left$(sToConvert, InStr(sToConvert, (Chr(0) & Chr(0))) - 1) If Len(sToConvert) Mod 2 <> 0 Then sToConvert = sToConvert & Chr(0) 'If the file has an ANSI extension or just an ANSI last character of 'a file with no extension, add one on the end 'If we don't add it, the string will end one character too short End If bFileName = StrConv(sToConvert, vbFromUnicode) 'Put the string into a byte array sBuf = "" For lRet = 0 To Len(sToConvert) - 1 Step 2 'At this point, the unicode characters will show up in sBuf as ?, but, when we actually go 'to use this in the FSO function, it will find the right file sBuf = sBuf & StrConv(Chr(bFileName(lRet)) & Chr(bFileName(lRet + 1)), vbFromUnicode) Next 'And return the string for use ConvertFileName = sBuf End Function Private Sub UnicodeSaveMethod() Dim sFileName As String 'Show the save dialog and get the file path as Unicode in a VB String sFileName = ShowSaveUnicode If Left$(sFileName, 1) = Chr(0) Then Exit Sub 'Exit on Cancel 'Convert the file name to be used sFileName = ConvertFileName(sFileName) 'Here is where you'd create the file, input the text, and save it 'For this example, I just try to create the file Dim FSO As FileSystemObject Set FSO = New FileSystemObject ' Dim f As TextStream ' Set f = FSO.CreateTextFile(sFileName, False) ' f.Close End Sub Private Sub UnicodeOpenMethod() Dim sFileName As String 'Show the open dialog and get the file path as Unicode in a VB String sFileName = ShowOpenUnicode If Left$(sFileName, 1) = Chr(0) Then Exit Sub 'Exit on Cancel 'Convert the file name to be used sFileName = ConvertFileName(sFileName) 'This line will print everything in the file to show you it works 'Otherwise, you'd have normal open/read/etc code here Debug.Print FSO.OpenTextFile(sFileName, ForReading, False, TristateUseDefault).ReadAll End Sub Private Sub Form_Load() Set FSO = New FileSystemObject End Sub Private Sub Form_Unload(Cancel As Integer) Set FSO = Nothing End Sub Private Sub Command1_Click() UnicodeOpenMethod End Sub Private Sub Command2_Click() UnicodeSaveMethod End Sub
for exmaple orginal data of (نمونه تصویر.png) is :
‰PNG
IHDR a E صYش sRGB ®خé gAMA ±ڈüa pHYs أ أاo¨d چIDATx^يط±چآ0@ل”””)ƒپR²%c0%#¤dŒ””œuù…’ثء»‚أژx¯KىHè“LىT7£4â4â4 â4â4â4â4â4â4â4â4â4â4â4â4â4â4â4â4â4âٍu]·كïW«U5.ف9ڈ1)kyŒN§سeعb±ˆ²–ا¨®ë`*âپ¬هù0n¸¸âض'¥Eمî‹+®?ظèp8„ء¸¦ iْ qةFXiô¤زèQi»BMKûةفn<Uµفnc k¥ےr¹*ھعl6×ë5ئ²V„رهrY¯×aَ]9@©جFam¸]*çکv/›Q¯3\\I*ي›b¸¤2MuRi*¥3
ë*F؟길~ô؟Fmغ¦wù£د هëô½قè/ك†و¢س÷z£ç@َزé{½رًL_×u:تںدç›goد*iqqqqqqqqqqqqqqqqqqqqqqqqqqQ ·غèO¹1ل¼ IEND®B`‚
but with my code in debug window data is :
‰PNG
? ? ? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ? ? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ? ? ???? ???? ???? ???? ???? ???? ???? ???? ??¦iú qýÉFXiô¤ÒèQi»BMKûÉÝn<UµÝnc k¥ÿr¹žªÚl6×ë5ƲV„ÑårY¯×aó]9@©ÌFýam¸]*ç˜v/›Q¯3\\I*í›b¸¤2MuRi*¥3
ë*F¿ê¸¸~ô¿FmÛ¦wù£Ï åëô½Þè/߆æ¢Ó÷z£ç@óÒé{½ÑðL_×u:ÊŸÏç›goýÏžiqqqqqqqqqqqqqqqqqqqq qqqqqqQ·ÛýèO¹1á¼ IEND®B`‚
how can fix this problem?
and then i want save it to like as "تصویر نمونه ذخیره شده.png" ( my means is unicode names) with same data content.but UnicodeSaveMethod is just creat text file.




Reply With Quote
