Results 1 to 8 of 8

Thread: Problems, just problems...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242

    Question

    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

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    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

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    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

  6. #6
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Exclamation 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!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    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

  8. #8
    Lively Member
    Join Date
    May 1999
    Location
    India
    Posts
    97
    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
  •  



Click Here to Expand Forum to Full Width