473,836 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UpdateResource being weird

Nak
Hi there,

It's probably me being weird more than the function but I'm having
problems with it doing as it should.

I have a C++ application with 2 resources of custom types,

RT_INIFILE @ 2000 (INI file)

and

IDR_MSISETUP @ 3000 (MSI file)

The declaration of my UpdateResource call is as follows,

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal lpType
As String, ByVal lpID As Integer, ByVal wLanguage As Integer, ByVal lpData()
As Byte, ByVal cbData As Integer) As Integer
End Function

Right, so here's the problem. When calling the above method to update
the 2 resources I get no errors returned, unfortunately further inspection
using a resource viewer shows that the MSI file is being updated (although
the resource viewer has trouble reading the data) and the INI file is not
updated, but kind of modified, it becomes 2 resource files within an item
called 2000, 1 the original INI file and 1 the new updated file (strange).

Now if I try the above method by changing the lpID parameter to a string
it says it's worked, but hasn't, which is rather strange too. So I'm
beginning to wonder if I'm getting the declaration wrong or something, but
if that's the case how comes it even attempts to update? Anyway, this is my
code that updates the resource

--- Start of file ---

Imports System.Runtime. InteropServices
Imports System.Componen tModel
Imports System.IO

Public Class resourceUpdater

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function BeginUpdateReso urce(ByVal pFileName As String, ByVal
bDeleteExisting Resources As Boolean) As IntPtr
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal lpType
As String, ByVal lpID As String, ByVal wLanguage As Integer, ByVal lpData()
As Byte, ByVal cbData As Integer) As Integer
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function EndUpdateResour ce(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceF romBuffer(ByVal iType As String, ByVal iID As
Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateReso urce(cStrFileNa me, False)
If (Not pIPrUpdating.Eq uals(IntPtr.Zer o)) Then
If (UpdateResource (pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResou rce(pIPrUpdatin g, False)) Then
Return (True)
Else
Throw New Exception("Fail ed to end updating of resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to update resource '" & iID.ToString
& "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to begin updating resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
End Function

Public Shared Function fromFile(ByVal iFileName As String) As
resourceUpdater
If (File.Exists(iF ileName)) Then
Dim pWRDResource As New resourceUpdater ()
pWRDResource.cS trFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundExc eption("The Win32 resource file could not
be found.", iFileName)
End If
End Function

End Class

--- End of file ---

Not much too it really, to update my resources I'm calling it like this,

Dim pRUrUpdater As resourceUpdater =
resourceUpdater .fromFile("c:\f ubar.exe")
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_MSII NSTALLER", 3000,
pBytMSIInstalle r)
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_INIF ILE", 2000,
pBytINIConfig)

Obviously the passed byte arrays contain the correct data, as I can see
in the resource viewer 1 of the INI files are correct, the other shouldn't
actually be there. The MSI installer seems to have been updated correctly
as I'm even extracting it from the executable again and then running it, but
the INI file is messing me arround.

Any tips on how to use this function or reasons as to why it isn't
working correctly? Thanks loads in advance, much appreciated!

Nick.
Nov 21 '05 #1
14 2978
Nak
Hi again,

Ignore the part about the resource viewer not being able to read the
updated MSI file, it turns out it's just a bug with the resource viewer, I'm
using ResHacker now and it's viewing it fine. But obviously my problem is
still here.

Nick.

"Nak" <a@a.com> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl...
Hi there,

It's probably me being weird more than the function but I'm having
problems with it doing as it should.

I have a C++ application with 2 resources of custom types,

RT_INIFILE @ 2000 (INI file)

and

IDR_MSISETUP @ 3000 (MSI file)

The declaration of my UpdateResource call is as follows,

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal
lpType As String, ByVal lpID As Integer, ByVal wLanguage As Integer, ByVal
lpData() As Byte, ByVal cbData As Integer) As Integer
End Function

Right, so here's the problem. When calling the above method to update
the 2 resources I get no errors returned, unfortunately further inspection
using a resource viewer shows that the MSI file is being updated (although
the resource viewer has trouble reading the data) and the INI file is not
updated, but kind of modified, it becomes 2 resource files within an item
called 2000, 1 the original INI file and 1 the new updated file (strange).

Now if I try the above method by changing the lpID parameter to a
string it says it's worked, but hasn't, which is rather strange too. So
I'm beginning to wonder if I'm getting the declaration wrong or something,
but if that's the case how comes it even attempts to update? Anyway, this
is my code that updates the resource

--- Start of file ---

Imports System.Runtime. InteropServices
Imports System.Componen tModel
Imports System.IO

Public Class resourceUpdater

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function BeginUpdateReso urce(ByVal pFileName As String,
ByVal bDeleteExisting Resources As Boolean) As IntPtr
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal
lpType As String, ByVal lpID As String, ByVal wLanguage As Integer, ByVal
lpData() As Byte, ByVal cbData As Integer) As Integer
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function EndUpdateResour ce(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceF romBuffer(ByVal iType As String, ByVal iID
As Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateReso urce(cStrFileNa me, False)
If (Not pIPrUpdating.Eq uals(IntPtr.Zer o)) Then
If (UpdateResource (pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResou rce(pIPrUpdatin g, False)) Then
Return (True)
Else
Throw New Exception("Fail ed to end updating of resource '"
& iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to update resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to begin updating resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
End Function

Public Shared Function fromFile(ByVal iFileName As String) As
resourceUpdater
If (File.Exists(iF ileName)) Then
Dim pWRDResource As New resourceUpdater ()
pWRDResource.cS trFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundExc eption("The Win32 resource file could not
be found.", iFileName)
End If
End Function

End Class

--- End of file ---

Not much too it really, to update my resources I'm calling it like
this,

Dim pRUrUpdater As resourceUpdater =
resourceUpdater .fromFile("c:\f ubar.exe")
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_MSII NSTALLER", 3000,
pBytMSIInstalle r)
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_INIF ILE", 2000,
pBytINIConfig)

Obviously the passed byte arrays contain the correct data, as I can see
in the resource viewer 1 of the INI files are correct, the other shouldn't
actually be there. The MSI installer seems to have been updated correctly
as I'm even extracting it from the executable again and then running it,
but the INI file is messing me arround.

Any tips on how to use this function or reasons as to why it isn't
working correctly? Thanks loads in advance, much appreciated!

Nick.

Nov 21 '05 #2
That's funny, I was working on updateresource just yesterday, only i was
working with png files in the RCDATA section.
This is how I declared UpdateResource:

\\\
<DllImport("ker nel32", CallingConventi on:=CallingConv ention.Cdecl, _
setlasterror:=T rue)> _
Public Function UpdateResource( ByVal hUpdate As IntPtr, _
ByVal lpType As IntPtr, _
ByVal lpName As System.Text.Str ingBuilder, _
ByVal wLanguage As Int16, _
ByVal lpData As Byte(), _
ByVal cbData As Int32) As Int32
End Function
///

and then I called it like this:

\\\
BeginUpdateReso urce(...
....
Dim ResID As New System.Text.Str ingBuilder(some string.ToUpper)
'ToUpper was crucial for extracting again using LoadResource
....
UpdateResource( hUpdateRes, _
New IntPtr(RT_RCDAT A), _
ResID, _
1033, _
someArray, _
someArray.Lengt h)
....
EndUpdateResour ce(...
///

You may need to add 'CharSet:=CharS et.Unicode' in the DllImport attribute
for String Types.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Nak" <a@a.com> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl...
Hi there,

It's probably me being weird more than the function but I'm having
problems with it doing as it should.

I have a C++ application with 2 resources of custom types,

RT_INIFILE @ 2000 (INI file)

and

IDR_MSISETUP @ 3000 (MSI file)

The declaration of my UpdateResource call is as follows,

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal
lpType As String, ByVal lpID As Integer, ByVal wLanguage As Integer, ByVal
lpData() As Byte, ByVal cbData As Integer) As Integer
End Function

Right, so here's the problem. When calling the above method to update
the 2 resources I get no errors returned, unfortunately further inspection
using a resource viewer shows that the MSI file is being updated (although
the resource viewer has trouble reading the data) and the INI file is not
updated, but kind of modified, it becomes 2 resource files within an item
called 2000, 1 the original INI file and 1 the new updated file (strange).

Now if I try the above method by changing the lpID parameter to a
string it says it's worked, but hasn't, which is rather strange too. So
I'm beginning to wonder if I'm getting the declaration wrong or something,
but if that's the case how comes it even attempts to update? Anyway, this
is my code that updates the resource

--- Start of file ---

Imports System.Runtime. InteropServices
Imports System.Componen tModel
Imports System.IO

Public Class resourceUpdater

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function BeginUpdateReso urce(ByVal pFileName As String,
ByVal bDeleteExisting Resources As Boolean) As IntPtr
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal
lpType As String, ByVal lpID As String, ByVal wLanguage As Integer, ByVal
lpData() As Byte, ByVal cbData As Integer) As Integer
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function EndUpdateResour ce(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceF romBuffer(ByVal iType As String, ByVal iID
As Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateReso urce(cStrFileNa me, False)
If (Not pIPrUpdating.Eq uals(IntPtr.Zer o)) Then
If (UpdateResource (pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResou rce(pIPrUpdatin g, False)) Then
Return (True)
Else
Throw New Exception("Fail ed to end updating of resource '"
& iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to update resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to begin updating resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
End Function

Public Shared Function fromFile(ByVal iFileName As String) As
resourceUpdater
If (File.Exists(iF ileName)) Then
Dim pWRDResource As New resourceUpdater ()
pWRDResource.cS trFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundExc eption("The Win32 resource file could not
be found.", iFileName)
End If
End Function

End Class

--- End of file ---

Not much too it really, to update my resources I'm calling it like
this,

Dim pRUrUpdater As resourceUpdater =
resourceUpdater .fromFile("c:\f ubar.exe")
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_MSII NSTALLER", 3000,
pBytMSIInstalle r)
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_INIF ILE", 2000,
pBytINIConfig)

Obviously the passed byte arrays contain the correct data, as I can see
in the resource viewer 1 of the INI files are correct, the other shouldn't
actually be there. The MSI installer seems to have been updated correctly
as I'm even extracting it from the executable again and then running it,
but the INI file is messing me arround.

Any tips on how to use this function or reasons as to why it isn't
working correctly? Thanks loads in advance, much appreciated!

Nick.

Nov 21 '05 #3
Nak
Hi Mick,

Thanks for the info, I shall go and give it a try now. I've been having
numerous problems with the DLLImports, I'm probably missing most of the
attributes that are crucial to getting it working. Anyway, thanks again!
:-)

Nick.

"Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in
message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
That's funny, I was working on updateresource just yesterday, only i was
working with png files in the RCDATA section.
This is how I declared UpdateResource:

\\\
<DllImport("ker nel32", CallingConventi on:=CallingConv ention.Cdecl, _
setlasterror:=T rue)> _
Public Function UpdateResource( ByVal hUpdate As IntPtr, _
ByVal lpType As IntPtr, _
ByVal lpName As System.Text.Str ingBuilder, _
ByVal wLanguage As Int16, _
ByVal lpData As Byte(), _
ByVal cbData As Int32) As Int32
End Function
///

and then I called it like this:

\\\
BeginUpdateReso urce(...
...
Dim ResID As New System.Text.Str ingBuilder(some string.ToUpper)
'ToUpper was crucial for extracting again using LoadResource
...
UpdateResource( hUpdateRes, _
New IntPtr(RT_RCDAT A), _
ResID, _
1033, _
someArray, _
someArray.Lengt h)
...
EndUpdateResour ce(...
///

You may need to add 'CharSet:=CharS et.Unicode' in the DllImport attribute
for String Types.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Nak" <a@a.com> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl...
Hi there,

It's probably me being weird more than the function but I'm having
problems with it doing as it should.

I have a C++ application with 2 resources of custom types,

RT_INIFILE @ 2000 (INI file)

and

IDR_MSISETUP @ 3000 (MSI file)

The declaration of my UpdateResource call is as follows,

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal
lpType As String, ByVal lpID As Integer, ByVal wLanguage As Integer,
ByVal lpData() As Byte, ByVal cbData As Integer) As Integer
End Function

Right, so here's the problem. When calling the above method to update
the 2 resources I get no errors returned, unfortunately further
inspection using a resource viewer shows that the MSI file is being
updated (although the resource viewer has trouble reading the data) and
the INI file is not updated, but kind of modified, it becomes 2 resource
files within an item called 2000, 1 the original INI file and 1 the new
updated file (strange).

Now if I try the above method by changing the lpID parameter to a
string it says it's worked, but hasn't, which is rather strange too. So
I'm beginning to wonder if I'm getting the declaration wrong or
something, but if that's the case how comes it even attempts to update?
Anyway, this is my code that updates the resource

--- Start of file ---

Imports System.Runtime. InteropServices
Imports System.Componen tModel
Imports System.IO

Public Class resourceUpdater

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function BeginUpdateReso urce(ByVal pFileName As String,
ByVal bDeleteExisting Resources As Boolean) As IntPtr
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal
lpType As String, ByVal lpID As String, ByVal wLanguage As Integer, ByVal
lpData() As Byte, ByVal cbData As Integer) As Integer
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function EndUpdateResour ce(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceF romBuffer(ByVal iType As String, ByVal iID
As Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateReso urce(cStrFileNa me, False)
If (Not pIPrUpdating.Eq uals(IntPtr.Zer o)) Then
If (UpdateResource (pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResou rce(pIPrUpdatin g, False)) Then
Return (True)
Else
Throw New Exception("Fail ed to end updating of resource '"
& iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to update resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to begin updating resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
End Function

Public Shared Function fromFile(ByVal iFileName As String) As
resourceUpdater
If (File.Exists(iF ileName)) Then
Dim pWRDResource As New resourceUpdater ()
pWRDResource.cS trFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundExc eption("The Win32 resource file could not
be found.", iFileName)
End If
End Function

End Class

--- End of file ---

Not much too it really, to update my resources I'm calling it like
this,

Dim pRUrUpdater As resourceUpdater =
resourceUpdater .fromFile("c:\f ubar.exe")
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_MSII NSTALLER", 3000,
pBytMSIInstalle r)
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_INIF ILE", 2000,
pBytINIConfig)

Obviously the passed byte arrays contain the correct data, as I can
see in the resource viewer 1 of the INI files are correct, the other
shouldn't actually be there. The MSI installer seems to have been
updated correctly as I'm even extracting it from the executable again and
then running it, but the INI file is messing me arround.

Any tips on how to use this function or reasons as to why it isn't
working correctly? Thanks loads in advance, much appreciated!

Nick.


Nov 21 '05 #4
Nak
BTW.
http://dotnetrix.co.uk/nothing.html


Very good, made me chuckle.

Nick.
Nov 21 '05 #5
Nak
At bl00dy last, this is my declaration,

<DllImport("ker nel32", CallingConventi on:=CallingConv ention.Cdecl,
setlasterror:=T rue)> _
Public Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal lpType
As StringBuilder, ByVal lpID As IntPtr, ByVal wLanguage As Int16, ByVal
lpData As Byte(), ByVal cbData As Int32) As Int32
End Function

It never ceases to amaze my how much you can twist these declarations and
end up with a working solution!

Nick.

"Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in
message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
That's funny, I was working on updateresource just yesterday, only i was
working with png files in the RCDATA section.
This is how I declared UpdateResource:

\\\
<DllImport("ker nel32", CallingConventi on:=CallingConv ention.Cdecl, _
setlasterror:=T rue)> _
Public Function UpdateResource( ByVal hUpdate As IntPtr, _
ByVal lpType As IntPtr, _
ByVal lpName As System.Text.Str ingBuilder, _
ByVal wLanguage As Int16, _
ByVal lpData As Byte(), _
ByVal cbData As Int32) As Int32
End Function
///

and then I called it like this:

\\\
BeginUpdateReso urce(...
...
Dim ResID As New System.Text.Str ingBuilder(some string.ToUpper)
'ToUpper was crucial for extracting again using LoadResource
...
UpdateResource( hUpdateRes, _
New IntPtr(RT_RCDAT A), _
ResID, _
1033, _
someArray, _
someArray.Lengt h)
...
EndUpdateResour ce(...
///

You may need to add 'CharSet:=CharS et.Unicode' in the DllImport attribute
for String Types.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Nak" <a@a.com> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl...
Hi there,

It's probably me being weird more than the function but I'm having
problems with it doing as it should.

I have a C++ application with 2 resources of custom types,

RT_INIFILE @ 2000 (INI file)

and

IDR_MSISETUP @ 3000 (MSI file)

The declaration of my UpdateResource call is as follows,

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal
lpType As String, ByVal lpID As Integer, ByVal wLanguage As Integer,
ByVal lpData() As Byte, ByVal cbData As Integer) As Integer
End Function

Right, so here's the problem. When calling the above method to update
the 2 resources I get no errors returned, unfortunately further
inspection using a resource viewer shows that the MSI file is being
updated (although the resource viewer has trouble reading the data) and
the INI file is not updated, but kind of modified, it becomes 2 resource
files within an item called 2000, 1 the original INI file and 1 the new
updated file (strange).

Now if I try the above method by changing the lpID parameter to a
string it says it's worked, but hasn't, which is rather strange too. So
I'm beginning to wonder if I'm getting the declaration wrong or
something, but if that's the case how comes it even attempts to update?
Anyway, this is my code that updates the resource

--- Start of file ---

Imports System.Runtime. InteropServices
Imports System.Componen tModel
Imports System.IO

Public Class resourceUpdater

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function BeginUpdateReso urce(ByVal pFileName As String,
ByVal bDeleteExisting Resources As Boolean) As IntPtr
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal
lpType As String, ByVal lpID As String, ByVal wLanguage As Integer, ByVal
lpData() As Byte, ByVal cbData As Integer) As Integer
End Function

<DllImport("ker nel32.dll", SetLastError:=T rue)> _
Private Shared Function EndUpdateResour ce(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceF romBuffer(ByVal iType As String, ByVal iID
As Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateReso urce(cStrFileNa me, False)
If (Not pIPrUpdating.Eq uals(IntPtr.Zer o)) Then
If (UpdateResource (pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResou rce(pIPrUpdatin g, False)) Then
Return (True)
Else
Throw New Exception("Fail ed to end updating of resource '"
& iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to update resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Fail ed to begin updating resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
End Function

Public Shared Function fromFile(ByVal iFileName As String) As
resourceUpdater
If (File.Exists(iF ileName)) Then
Dim pWRDResource As New resourceUpdater ()
pWRDResource.cS trFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundExc eption("The Win32 resource file could not
be found.", iFileName)
End If
End Function

End Class

--- End of file ---

Not much too it really, to update my resources I'm calling it like
this,

Dim pRUrUpdater As resourceUpdater =
resourceUpdater .fromFile("c:\f ubar.exe")
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_MSII NSTALLER", 3000,
pBytMSIInstalle r)
Call pRUrUpdater.upd ateResourceFrom Buffer("RT_INIF ILE", 2000,
pBytINIConfig)

Obviously the passed byte arrays contain the correct data, as I can
see in the resource viewer 1 of the INI files are correct, the other
shouldn't actually be there. The MSI installer seems to have been
updated correctly as I'm even extracting it from the executable again and
then running it, but the INI file is messing me arround.

Any tips on how to use this function or reasons as to why it isn't
working correctly? Thanks loads in advance, much appreciated!

Nick.


Nov 21 '05 #6
I had this free webspace for years and never had Anything to put on it, so
one day, when I was bored, I put Nothing on it.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Nak" <a@a.com> wrote in message
news:eY******** ********@TK2MSF TNGP11.phx.gbl. ..
BTW.
http://dotnetrix.co.uk/nothing.html


Very good, made me chuckle.

Nick.

Nov 21 '05 #7
I use several overloaded versions depending on what I want to add.

I never managed to get EnumResources working, but I suppose that's because I
wasn't persistant enough.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Nak" <a@a.com> wrote in message
news:uK******** ******@TK2MSFTN GP12.phx.gbl...
At bl00dy last, this is my declaration,

<DllImport("ker nel32", CallingConventi on:=CallingConv ention.Cdecl,
setlasterror:=T rue)> _
Public Shared Function UpdateResource( ByVal hUpdate As IntPtr, ByVal
lpType As StringBuilder, ByVal lpID As IntPtr, ByVal wLanguage As Int16,
ByVal lpData As Byte(), ByVal cbData As Int32) As Int32
End Function

It never ceases to amaze my how much you can twist these declarations and
end up with a working solution!

Nick.

Nov 21 '05 #8
"Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> schrieb:
I never managed to get EnumResources working, but I suppose that's because
I wasn't persistant enough.


Some declarations can be found in this sample:

<URL:http://dotnet.mvps.org/dotnet/samples/tools/ThemeUtil.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9
Thanks Herfried!
It's annoying seeing just how close I was.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:OL******** ******@TK2MSFTN GP09.phx.gbl...
"Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]>
schrieb:
I never managed to get EnumResources working, but I suppose that's
because I wasn't persistant enough.


Some declarations can be found in this sample:

<URL:http://dotnet.mvps.org/dotnet/samples/tools/ThemeUtil.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2371
by: Gabriel Afana | last post by:
I have a simple php script to just send email.....When I first load the script in a browser...it sends 2 emails. Why?? The weird thing is then when I refresh the page, it send only one email...I can refresh the page a million times and each time it only sends 1 email. But its the first time the page is loaded (like I open a new IE browser and go to the script), it sends 2 emails (duplicates). The entire script is below: <?php $to...
3
2082
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed to get a working system just about finished. I am building an interface for our customer service folks to use to manage registered customers and am seeing some weird behavior.
82
5399
by: nobody | last post by:
Howdy, Mike! mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0402271647.c20aea3@posting.google.com>... > I'm a C++ programmer, and have to use lisp because I want to use > emacs. I've gotten a book on lisp, and I must say lisp is the ugliest > looking language syntax wise. What is up with this: (defun(foo()). (DEFUN FOO () NIL) > What were the lisp authors thinking? Why did Stallman use lisp in
0
3038
by: John Dyer | last post by:
We need to be able to set the version information for .net exe's and dll's after the build has happened. This is so we do not need to check out files that have not changed just to "tweak" the version data. I am trying to emulate the functionality that Dev Studio has where I have been able to change the version information by loading in a dll or exe and selecting the version resource. I then am able to "drill" down to the version...
10
7946
by: tsahiasher | last post by:
hi, i'm trying to use the Win32 API UpdateResource function to add a file to an exe file, but somehow i'm getting a NullReferenceException when i call the function. here is a piece of the code: GCHandle gch = GCHandle.Alloc(fileBuffComp); if (UpdateResource(hResource, "FILE", fileName, MakeLangId(0x09, 0x01), /* */(IntPtr)gch, compFileLen) == false) { throw new Win32Exception(Marshal.GetLastWin32Error());
6
3015
by: Klaatu | last post by:
I've seen plenty of examples of updating a resource using UpdateResource(). Has anyone actually used it to add a new resource? For example, a menu resource. If so, how is it done? I'm not quit sure how to present the raw data. -- Gort, Klaatu, Barrada Nikto...
2
1956
by: Hades | last post by:
Hi, I'm trying to change some of resources within a compiled exe with the updaterecource API in Visual Basic. But I just can't figure out how I should do it. Searching the internet didn't help me either. I hope that some one can provide me some code to help me. To make it a bit more clear (I hope): What I'm trying to do is editing some string tables within an exe using the updateresource API. Resource editing using programs like reshack...
3
5493
by: aling | last post by:
Execute following T-SQL within Queary Analyzer of SQL Server 2000: ======================================= DECLARE @dTest DATETIME SET @dTest='2001-1-1 1:1:1:991' SELECT @dTest SET @dTest='2001-1-1 1:1:1:997' SELECT @dTest
0
1836
by: P Pulkkinen | last post by:
Dear all, sorry, i know this code is far little too long to debug here, but there is really annoying logical error. If someone debugs this, I really offer warm virtual handshake. What this code SHOULD do: - read new (=updated) licensetext from file $license_path then - read and modify recursively all files from $current_dir, replacing old
0
10852
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10255
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6980
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4459
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4021
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.