Jump to content
  • Advertisement
Sign in to follow this  
Maurice

[web] Question about parameter passing with OCX

This topic is 3948 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have been struggling with passing parameters to an OCX (activeX) via a html page. The html code I use is as follows:
<HTML>
  <HEAD>
    <TITLE>FIS-viewer panoramic viewer</TITLE>
  </HEAD>

  <CENTER>
  <OBJECT NAME     ="FIS"
          ID       ="FISViewer" 
          CLASSID  ="CLSID:46102D2F-DB86-444A-BD10-A61C3D0A03FC"
          WIDTH    =640
          HEIGHT   =480
          CODEBASE ="fisviewer.ocx">
         <PARAM NAME ="File" VALUE="E:\Project\Images\Panaramic1.jpg">
  </OBJECT>
  </CENTER>

  <BODY>
    <SCRIPT LANGUAGE="JavaScript">
      FIS.File="E:\Project\Images\Panaramic1.jpg"
    </SCRIPT>
  </BODY>
</HTML>

The OCX fisviewer is a panoramic viewer written in VC++ 2005. What I would like is once the HTML page is opened and the OCX is executed that it loads and displays the image file that is supplied in the HTML code. Eighter via <PARAM NAME="" VALUE=""> or via directly calling properties of the OCX file. The File in the call FIS.File is property of the fisviewer.h/.cpp class project and it's got a get and set function implemented for it, see below for some code fragments. Header file.
class CFisviewerApp : public COleControlModule
{
  private:
    LPCTSTR File;

  public:
    // Constructor
    CFisviewerApp();

    int ExitInstance();

    BOOL InitInstance();

    // Get/Set function for the property "File"
    LPCTSTR GetFile( );
    void SetFile( LPCTSTR FileName );

};

Source file.
LPCTSTR CFisviewerApp::GetFile( )
{
  return this->File;
}

void CFisviewerApp::SetFile( LPCTSTR FileName )
{
  this->File = FileName;
}

I have looked all over the internet but I haven't found a solution yet. Most information was in Visual Basic. Can anyone direct me to a site that has some good tutorials on OCX and VC++ or can anyone help me modify the OCX project in such a way that the OCX file is loading the file supplied in the html page. Thanks

Share this post


Link to post
Share on other sites
Advertisement
First of all, you seem to be passing C style strings around. In COM code, you are supposed to use BSTR. See MSDN docs: SysAllocString, SysFreeString, etc.

Second, your getters/setters must be registered as COM interface properties. See MIDL language reference and TLB file format for more information. Your getters/setters must also be created in a special way, adhering to COM programming guidelines. You made no mention of how you implemented those, so I don't know why it might not be working for you.

Share this post


Link to post
Share on other sites
My knowledge of windows programming is rather limited. I got this project from a friend who got it from someone in india. I was made in VC++ 6 and I converted it to VC++ 8. After that I removed a number of bugs in the code and got it to work as an exe.

A little later I got to work on the OCX version and save for a few minor bugs I got it to compile.

How do I pass on parameters via HTML then ? what's wrong in the html code I supplied last time ?

I have been looking all over VC++ 2005 before but I haven't found anything that would let me define a property for the fisviewer class and create a special getter and setter function for that class so that I can call the property in the html document.

how do I proceed from here ?

Share this post


Link to post
Share on other sites
They removed all that from VS2005, so you can't do easily any more. Only VS6 could do it. You will have to either browse the docs (ATL/MFC or whatever you are using) or get Visual Studio 6 and see how it does it.

Share this post


Link to post
Share on other sites
I got the OCX working by using Functions and Properties. Was rather simple, now that I have figured out how to do it.

The only thing I like to know is how I can read those param fields that you can supply to the object that you create.

if anyone knows how I could do that I would appriciate a link or a small example how it is done..

thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Maurice
I got the OCX working by using Functions and Properties. Was rather simple, now that I have figured out how to do it.

You might post the solution for the next guy that is searching for the same problem...

Quote:
The only thing I like to know is how I can read those param fields that you can supply to the object that you create.

if anyone knows how I could do that I would appriciate a link or a small example how it is done..

thanks


I'm not sure what you mean. Do you want to be able to have Intellisense tell you the names of the parameters, or do you want to be able to read back a value from method, or what?

Share this post


Link to post
Share on other sites
I would like to be able to read out the parameter. Much like the parameters in the command line that you get with "void main( int argc, char *argv )".

I just want a way to read out those parameters and do stuff in the ocx with the information contained within those parameters that are supplied with the <object> </object>.

As for the solution to be able to use methods and properties of an OCX from an html page. Go to the class view of your project, find the interface of your OCX project. It's small gray bar with a gray ball on its left end. Right click on that and go to add. There you will find the functionality to add a method or property to the project who are callable from outside a html page.

And if you want to call a function in your document from the outside you will have to create a view to the class that contains the function you want to call and then you can just call it.

Below there are 2 code snips. The first one is a constructor of the ctrl class that is automaticaly created when you create an ActiveX MFC project. That class will hold the OCX methods and properties. In the constructor the document is created with a doc, frame and view. Now to be able to call for example a function from the CAppView like I needed see the second code snip.


CFisviewerCtrl::CFisviewerCtrl()
{
InitializeIIDs(&IID_DFisviewer, &IID_DFisviewerEvents);

// TODO: Initialize your control's instance data here.
SetInitialSize(200, 200);

AddDocTemplate(new CActiveXDocTemplate(
RUNTIME_CLASS(CAppDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CAppView)));
}




void CFisviewerCtrl::LoadFile( LPCTSTR FileName )
{
CView *pView =NULL;

CMDIFrameWnd *pFrame =NULL;
CMDIChildWnd *pChild =NULL;

AFX_MANAGE_STATE( AfxGetStaticModuleState( ));

pFrame =(CMDIFrameWnd *)AfxGetApp( )->m_pMainWnd;
pChild =(CMDIChildWnd *)pFrame->GetActiveFrame( );
pView =(CAppView *)pChild->GetActiveView( );

// This call will, in my case, call the loadimage function in my OCX
pView->LoadImage( FileName );

// I use the code below, above is the same code, but easier on the eye
// ((CAppView *)pChild->GetActiveView( ))->LoadImage( FileName );
((CFisviewerApp*) AfxGetApp())->SetFile((LPCTSTR) FileName);
}



I hope this helps.

now I only need to get my head around the parameter reading and I'am all done

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!