|
-
Jul 12th, 2000, 06:26 AM
#1
Thread Starter
Addicted Member
Hello!
I'm currently developing class for loading resources from resource-only DLL. And I've encounterd one quite strange error. My function looks like this:
Code:
Public Function LoadPicResource(pic as PictureBox, id as long, resType as String) as Boolean
''
'' here is some other code
''
Set pic.Picture = LoadPicture(sFile)
End Function
When I try to compile it, I get compile error: Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as field of public user defined types.
I presume that error occured because of "pic as PictureBox", but I don't know how to repair that. I tried also like this:
Code:
Public Function LoadPicResource(id as long, resType as String) as StdPicure
''
'' here is some other code
''
Set LoadPicResource = LoadPicture(sFile)
End Function
But that also didn't work. When when I tried to run it and it came to line "Set LoadPicResource = LoadPicture(sFile)" it generated an error and VB then crashed. The error was "50002 - Unexpected error". I also tried to define my function as IPictureDisp but VB also crashed. I just don't get it why this happens, because LoadPicture() function is also declared as IPictureDisp.
Is there any way that I can create picture directly to PictureBox through hWnd property or something like that?
Zvonko
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
-
Jul 12th, 2000, 06:39 AM
#2
_______
<?>
It's occuring because it is declared public..
set it in a module or declare it private whichever
is needed for the procedure..
Public Function LoadPicResource(pic as PictureBox, id as long, resType as String) as Boolean
Private Function....or .bas module
[Edited by HeSaidJoe on 07-12-2000 at 07:42 AM]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jul 12th, 2000, 08:44 AM
#3
Thread Starter
Addicted Member
I could do that, but I need it in Class Module.
Any solutions?
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
-
Jul 12th, 2000, 09:20 AM
#4
Something else must be going on because when I create a class that contains your posted code and then do this
Code:
Option Explicit
Public C As Class1
Private Sub Form_Load()
Set C = New Class1
C.LoadPicResource Picture1, 123, "xxx"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set C = Nothing
End Sub
it runs and compiles OK.
-
Jul 12th, 2000, 05:01 PM
#5
Thread Starter
Addicted Member
Let me explain what my procedure really does.
It uses three parameters, picturebox, resource ID and resource type. First it extracts JPEG picture data from resource-only dll and saves it to disk file. Then I set myFunction=loadPicture(file). Maybe there's a problem because of that, but I don't know why. It stops where I set loadpicture(file) to my function and crashes VB.
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
-
Jul 12th, 2000, 05:47 PM
#6
Guru
This could be it.
Something is crashing: Either loading the picture, or setting it to the function.
Here's how you check. Change this line:
Code:
Set MyFunction = LoadPicture(File)
To this:
Code:
Dim oTest As Object
Set oTest = LoadPicture(File)
Set MyFunction = oTest
The 1st line isn't crashing. (Unless you have 8 KB of total RAM or something)
Either the 2nd or 3rd lines are crashing. Step through the code and check.
If it's the 2nd file, then maybe there's a problem with extracting the file, or maybe you didn't close it properly after extracting, or maybe the file isn't saved to the DLL correctly. Anything's possible.
If it's the 3rd line, then maybe you should do a manual Set instead. You do this using CopyMemory and the object's pointer. It's probably the 2nd line crashing, though.
Try!
-
Jul 12th, 2000, 06:19 PM
#7
Thread Starter
Addicted Member
Thanks.
I'll try this tomorrow, because here in Slovenia is late, 1 am. Can you post me an example with copymemory if that doesn't work?
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
-
Jul 13th, 2000, 01:06 AM
#8
Lively Member
hokay,
this is a rather common n VERY irritating VB error Question, where is the "pic" for the first version of your function Dim'd?? is it in that class module itself?? If it is then in ALL probability its Private n theres your error... make it public n check again.
If not n u're passing it over.. try specifically saying "ByRef Pic as PictureBox", even though the default is ByRef in VB this does do the trick sometimes...
if not.. well then we'll just have to see the rest of the code making up your class..
cheers
Gaurav
[email protected]
" Programming today is a race between software-engineers striving to build bigger and
better idiot-proof programs and the universe trying to produce bigger and better idiots.
So far the universe is winning". :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|