Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. COM
  4. Invalid Procedure call or argument in VB Client ?

Invalid Procedure call or argument in VB Client ?

Scheduled Pinned Locked Moved COM
questioncomsysadmindata-structureshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viral_umang hotmail com
    wrote on last edited by
    #1

    Hi all! I am writing COM Server.I am using User defined data type a Student structure in COM Server. There is a method in COM Server that returns the 1 st ranked student out of the student array passed to it from vb client. The Interface method is like this. STDMETHODIMP CStudentUtil::GetFirstRankStudent(SAFEARRAY **StudentArray,Student *pStudent) { if(!StudentArray) return(E_POINTER); if(!pStudent) return(E_INVALIDARG); long lBound=-1; long UBound=-1; Student *ob1=NULL,*ob2=NULL,*max=NULL; HRESULT hr; hr=::SafeArrayGetUBound(*StudentArray,1,&UBound); hr=::SafeArrayGetLBound(*StudentArray,1,&lBound); hr=::SafeArrayGetElement(*StudentArray,&lBound,(void*)ob1); max=ob1; if(FAILED(hr)) return hr; for(long i=lBound+1;iTotal>ob1->Total)/*Total is the member of my Student structure*/ max=ob2; } } pStudent=max; return S_OK; } The client side is Dim d As STUDENTLib.Student Set ob = New STUDENTLib.StudentUtil d = ob.GetFirstRankStudent(a) Set ob = Nothing What is wrong with the code in the client side that result in Invalid Procedure call or argument. Pls help on this. Thanks in advance. Viral Joshi.

    L 1 Reply Last reply
    0
    • V viral_umang hotmail com

      Hi all! I am writing COM Server.I am using User defined data type a Student structure in COM Server. There is a method in COM Server that returns the 1 st ranked student out of the student array passed to it from vb client. The Interface method is like this. STDMETHODIMP CStudentUtil::GetFirstRankStudent(SAFEARRAY **StudentArray,Student *pStudent) { if(!StudentArray) return(E_POINTER); if(!pStudent) return(E_INVALIDARG); long lBound=-1; long UBound=-1; Student *ob1=NULL,*ob2=NULL,*max=NULL; HRESULT hr; hr=::SafeArrayGetUBound(*StudentArray,1,&UBound); hr=::SafeArrayGetLBound(*StudentArray,1,&lBound); hr=::SafeArrayGetElement(*StudentArray,&lBound,(void*)ob1); max=ob1; if(FAILED(hr)) return hr; for(long i=lBound+1;iTotal>ob1->Total)/*Total is the member of my Student structure*/ max=ob2; } } pStudent=max; return S_OK; } The client side is Dim d As STUDENTLib.Student Set ob = New STUDENTLib.StudentUtil d = ob.GetFirstRankStudent(a) Set ob = Nothing What is wrong with the code in the client side that result in Invalid Procedure call or argument. Pls help on this. Thanks in advance. Viral Joshi.

      L Offline
      L Offline
      Lim Bio Liong
      wrote on last edited by
      #2

      Hello Joshi, I ran through your example and discovered one -possible- point of the E_INVALIDARG error occurs at the following line of code : hr=::SafeArrayGetElement(*StudentArray,&i,(void*)ob2); I declared the GetFirstRankStudent() method as follows : HRESULT GetFirstRankStudent([in] SAFEARRAY(Student)* pStudentArray, [out, retval] Student* pStudent); The SafeArrayGetElement() API makes a COPY of the required element of the array and so you must pass a pointer to an actual Student struct object (memory allocated for it already). Your code above sends a NULL pointer as the 3rd parameter (i.e. ob2). This is the reason for the E_INVALIDARG error. As a suggestion, I changed your code to as follows : //Student *ob1=NULL,*ob2=NULL,*max=NULL; Student ob2,*max=NULL; Student ob1; ... hr=::SafeArrayGetElement(*StudentArray,&lBound,(void*)&ob1); max=&ob1; if(FAILED(hr)) // this was where the original E_INVALIDARG appeared. return hr; for(long i=lBound+1;i < UBound; i++) { hr=::SafeArrayGetElement(*StudentArray,&i,(void*)&ob2); if(FAILED(hr)) return hr; else { if(ob2.Total>ob1.Total) max=&ob2; } } memcpy (pStudent, max, sizeof(Student)); return S_OK; Best Regards, Bio.

      V 1 Reply Last reply
      0
      • L Lim Bio Liong

        Hello Joshi, I ran through your example and discovered one -possible- point of the E_INVALIDARG error occurs at the following line of code : hr=::SafeArrayGetElement(*StudentArray,&i,(void*)ob2); I declared the GetFirstRankStudent() method as follows : HRESULT GetFirstRankStudent([in] SAFEARRAY(Student)* pStudentArray, [out, retval] Student* pStudent); The SafeArrayGetElement() API makes a COPY of the required element of the array and so you must pass a pointer to an actual Student struct object (memory allocated for it already). Your code above sends a NULL pointer as the 3rd parameter (i.e. ob2). This is the reason for the E_INVALIDARG error. As a suggestion, I changed your code to as follows : //Student *ob1=NULL,*ob2=NULL,*max=NULL; Student ob2,*max=NULL; Student ob1; ... hr=::SafeArrayGetElement(*StudentArray,&lBound,(void*)&ob1); max=&ob1; if(FAILED(hr)) // this was where the original E_INVALIDARG appeared. return hr; for(long i=lBound+1;i < UBound; i++) { hr=::SafeArrayGetElement(*StudentArray,&i,(void*)&ob2); if(FAILED(hr)) return hr; else { if(ob2.Total>ob1.Total) max=&ob2; } } memcpy (pStudent, max, sizeof(Student)); return S_OK; Best Regards, Bio.

        V Offline
        V Offline
        viral_umang hotmail com
        wrote on last edited by
        #3

        Thanks for the kind co-operation. I've also found the same error. Now the code is working fine. Once again thanks for your efforts. Viral Joshi

        L 1 Reply Last reply
        0
        • V viral_umang hotmail com

          Thanks for the kind co-operation. I've also found the same error. Now the code is working fine. Once again thanks for your efforts. Viral Joshi

          L Offline
          L Offline
          Lim Bio Liong
          wrote on last edited by
          #4

          Most welcome, Joshi. - Bio.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups