473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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("kernel32.dll", SetLastError:=True)> _
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.ComponentModel
Imports System.IO

Public Class resourceUpdater

<DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function BeginUpdateResource(ByVal pFileName As String, ByVal
bDeleteExistingResources As Boolean) As IntPtr
End Function

<DllImport("kernel32.dll", SetLastError:=True)> _
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("kernel32.dll", SetLastError:=True)> _
Private Shared Function EndUpdateResource(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceFromBuffer(ByVal iType As String, ByVal iID As
Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateResource(cStrFileName, False)
If (Not pIPrUpdating.Equals(IntPtr.Zero)) Then
If (UpdateResource(pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResource(pIPrUpdating, False)) Then
Return (True)
Else
Throw New Exception("Failed to end updating of resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed to update resource '" & iID.ToString
& "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed 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(iFileName)) Then
Dim pWRDResource As New resourceUpdater()
pWRDResource.cStrFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundException("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:\fubar.exe")
Call pRUrUpdater.updateResourceFromBuffer("RT_MSIINSTAL LER", 3000,
pBytMSIInstaller)
Call pRUrUpdater.updateResourceFromBuffer("RT_INIFILE", 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 2926
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**************@TK2MSFTNGP09.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("kernel32.dll", SetLastError:=True)> _
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.ComponentModel
Imports System.IO

Public Class resourceUpdater

<DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function BeginUpdateResource(ByVal pFileName As String,
ByVal bDeleteExistingResources As Boolean) As IntPtr
End Function

<DllImport("kernel32.dll", SetLastError:=True)> _
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("kernel32.dll", SetLastError:=True)> _
Private Shared Function EndUpdateResource(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceFromBuffer(ByVal iType As String, ByVal iID
As Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateResource(cStrFileName, False)
If (Not pIPrUpdating.Equals(IntPtr.Zero)) Then
If (UpdateResource(pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResource(pIPrUpdating, False)) Then
Return (True)
Else
Throw New Exception("Failed to end updating of resource '"
& iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed to update resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed 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(iFileName)) Then
Dim pWRDResource As New resourceUpdater()
pWRDResource.cStrFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundException("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:\fubar.exe")
Call pRUrUpdater.updateResourceFromBuffer("RT_MSIINSTAL LER", 3000,
pBytMSIInstaller)
Call pRUrUpdater.updateResourceFromBuffer("RT_INIFILE", 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("kernel32", CallingConvention:=CallingConvention.Cdecl, _
setlasterror:=True)> _
Public Function UpdateResource(ByVal hUpdate As IntPtr, _
ByVal lpType As IntPtr, _
ByVal lpName As System.Text.StringBuilder, _
ByVal wLanguage As Int16, _
ByVal lpData As Byte(), _
ByVal cbData As Int32) As Int32
End Function
///

and then I called it like this:

\\\
BeginUpdateResource(...
....
Dim ResID As New System.Text.StringBuilder(somestring.ToUpper)
'ToUpper was crucial for extracting again using LoadResource
....
UpdateResource(hUpdateRes, _
New IntPtr(RT_RCDATA), _
ResID, _
1033, _
someArray, _
someArray.Length)
....
EndUpdateResource(...
///

You may need to add 'CharSet:=CharSet.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**************@TK2MSFTNGP09.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("kernel32.dll", SetLastError:=True)> _
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.ComponentModel
Imports System.IO

Public Class resourceUpdater

<DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function BeginUpdateResource(ByVal pFileName As String,
ByVal bDeleteExistingResources As Boolean) As IntPtr
End Function

<DllImport("kernel32.dll", SetLastError:=True)> _
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("kernel32.dll", SetLastError:=True)> _
Private Shared Function EndUpdateResource(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceFromBuffer(ByVal iType As String, ByVal iID
As Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateResource(cStrFileName, False)
If (Not pIPrUpdating.Equals(IntPtr.Zero)) Then
If (UpdateResource(pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResource(pIPrUpdating, False)) Then
Return (True)
Else
Throw New Exception("Failed to end updating of resource '"
& iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed to update resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed 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(iFileName)) Then
Dim pWRDResource As New resourceUpdater()
pWRDResource.cStrFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundException("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:\fubar.exe")
Call pRUrUpdater.updateResourceFromBuffer("RT_MSIINSTAL LER", 3000,
pBytMSIInstaller)
Call pRUrUpdater.updateResourceFromBuffer("RT_INIFILE", 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.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:%2***************@TK2MSFTNGP12.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("kernel32", CallingConvention:=CallingConvention.Cdecl, _
setlasterror:=True)> _
Public Function UpdateResource(ByVal hUpdate As IntPtr, _
ByVal lpType As IntPtr, _
ByVal lpName As System.Text.StringBuilder, _
ByVal wLanguage As Int16, _
ByVal lpData As Byte(), _
ByVal cbData As Int32) As Int32
End Function
///

and then I called it like this:

\\\
BeginUpdateResource(...
...
Dim ResID As New System.Text.StringBuilder(somestring.ToUpper)
'ToUpper was crucial for extracting again using LoadResource
...
UpdateResource(hUpdateRes, _
New IntPtr(RT_RCDATA), _
ResID, _
1033, _
someArray, _
someArray.Length)
...
EndUpdateResource(...
///

You may need to add 'CharSet:=CharSet.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**************@TK2MSFTNGP09.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("kernel32.dll", SetLastError:=True)> _
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.ComponentModel
Imports System.IO

Public Class resourceUpdater

<DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function BeginUpdateResource(ByVal pFileName As String,
ByVal bDeleteExistingResources As Boolean) As IntPtr
End Function

<DllImport("kernel32.dll", SetLastError:=True)> _
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("kernel32.dll", SetLastError:=True)> _
Private Shared Function EndUpdateResource(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceFromBuffer(ByVal iType As String, ByVal iID
As Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateResource(cStrFileName, False)
If (Not pIPrUpdating.Equals(IntPtr.Zero)) Then
If (UpdateResource(pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResource(pIPrUpdating, False)) Then
Return (True)
Else
Throw New Exception("Failed to end updating of resource '"
& iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed to update resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed 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(iFileName)) Then
Dim pWRDResource As New resourceUpdater()
pWRDResource.cStrFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundException("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:\fubar.exe")
Call pRUrUpdater.updateResourceFromBuffer("RT_MSIINSTAL LER", 3000,
pBytMSIInstaller)
Call pRUrUpdater.updateResourceFromBuffer("RT_INIFILE", 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("kernel32", CallingConvention:=CallingConvention.Cdecl,
setlasterror:=True)> _
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.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:%2***************@TK2MSFTNGP12.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("kernel32", CallingConvention:=CallingConvention.Cdecl, _
setlasterror:=True)> _
Public Function UpdateResource(ByVal hUpdate As IntPtr, _
ByVal lpType As IntPtr, _
ByVal lpName As System.Text.StringBuilder, _
ByVal wLanguage As Int16, _
ByVal lpData As Byte(), _
ByVal cbData As Int32) As Int32
End Function
///

and then I called it like this:

\\\
BeginUpdateResource(...
...
Dim ResID As New System.Text.StringBuilder(somestring.ToUpper)
'ToUpper was crucial for extracting again using LoadResource
...
UpdateResource(hUpdateRes, _
New IntPtr(RT_RCDATA), _
ResID, _
1033, _
someArray, _
someArray.Length)
...
EndUpdateResource(...
///

You may need to add 'CharSet:=CharSet.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**************@TK2MSFTNGP09.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("kernel32.dll", SetLastError:=True)> _
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.ComponentModel
Imports System.IO

Public Class resourceUpdater

<DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function BeginUpdateResource(ByVal pFileName As String,
ByVal bDeleteExistingResources As Boolean) As IntPtr
End Function

<DllImport("kernel32.dll", SetLastError:=True)> _
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("kernel32.dll", SetLastError:=True)> _
Private Shared Function EndUpdateResource(ByVal hUpdate As IntPtr, ByVal
fDiscard As Boolean) As Boolean
End Function

Private cStrFileName As String

Public Function updateResourceFromBuffer(ByVal iType As String, ByVal iID
As Integer, ByVal iBuffer() As Byte) As Boolean
Dim pIPrUpdating As IntPtr = BeginUpdateResource(cStrFileName, False)
If (Not pIPrUpdating.Equals(IntPtr.Zero)) Then
If (UpdateResource(pIPrUpdating, iType, iID.ToString, 0, iBuffer,
iBuffer.Length) = 1) Then
If (EndUpdateResource(pIPrUpdating, False)) Then
Return (True)
Else
Throw New Exception("Failed to end updating of resource '"
& iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed to update resource '" &
iID.ToString & "' of type '" & iType & "'.")
End If
Else
Throw New Exception("Failed 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(iFileName)) Then
Dim pWRDResource As New resourceUpdater()
pWRDResource.cStrFileName = iFileName
Return (pWRDResource)
Else
Throw New FileNotFoundException("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:\fubar.exe")
Call pRUrUpdater.updateResourceFromBuffer("RT_MSIINSTAL LER", 3000,
pBytMSIInstaller)
Call pRUrUpdater.updateResourceFromBuffer("RT_INIFILE", 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****************@TK2MSFTNGP11.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**************@TK2MSFTNGP12.phx.gbl...
At bl00dy last, this is my declaration,

<DllImport("kernel32", CallingConvention:=CallingConvention.Cdecl,
setlasterror:=True)> _
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.SQUAREBRACKETS.[mdaudi100#ntlworld.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**************@TK2MSFTNGP09.phx.gbl...
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.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
Nak
Hi Mick,
It's annoying seeing just how close I was.


That's the law of the sod for you, spend 3 days trying to do something
and end up back where you started with only a slight modification. Don't
you love it when that happens?

Nick.
Nov 21 '05 #11
I only spent a couple of hours on this, but I know what you mean.
Only 3 days would be nice though. I spent months (on and off) trying to
resolve this solution:
http://dotnetrix.co.uk/misc.html --> Get Alpha Bitmap from 32 bit Icon, just
to end up finding that it was so simple.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Nak" <a@a.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Mick,
> It's annoying seeing just how close I was.


That's the law of the sod for you, spend 3 days trying to do something
and end up back where you started with only a slight modification. Don't
you love it when that happens?

Nick.

Nov 21 '05 #12
Nak
Hi Mick,
http://dotnetrix.co.uk/misc.html --> Get Alpha Bitmap from 32 bit Icon,
just to end up finding that it was so simple.


Aah, actually I have a question regarding that, does it mean that you
can put nice XP icons into an image list and then have them loaded
correctly? Or you have to set the icons for each item at run-time? I've
always wanted to up my icons like this but don't really wan't to set the
icons at runtime (although it's not particularly difficult), can the
ImageList be inherited from? Just wondering.

Nick.
Nov 21 '05 #13
Unfortunately, ImageLists flatten the Alpha Channel.
I have reported this as a Bug and it has been fixed in VS2005, (but not in
the Beta1 release).

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Nak" <a@a.com> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl...
Hi Mick,
http://dotnetrix.co.uk/misc.html --> Get Alpha Bitmap from 32 bit Icon,
just to end up finding that it was so simple.


Aah, actually I have a question regarding that, does it mean that you
can put nice XP icons into an image list and then have them loaded
correctly? Or you have to set the icons for each item at run-time? I've
always wanted to up my icons like this but don't really wan't to set the
icons at runtime (although it's not particularly difficult), can the
ImageList be inherited from? Just wondering.

Nick.

Nov 21 '05 #14
Nak
Hi Mick,
Unfortunately, ImageLists flatten the Alpha Channel.
I have reported this as a Bug and it has been fixed in VS2005, (but not in
the Beta1 release).


Aah right, fair enough. I suppose I should get on with my 1001 other
things then ;-)

Nick.
Nov 21 '05 #15

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

Similar topics

2
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...
3
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...
82
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 >...
0
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...
10
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: ...
6
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...
2
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...
3
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.