Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Using a VB ActiveX control in VC++

Hello experts,

If the task below is possible to achieve and someone can give me some sample code and the procedure to add the control to the project, I will give him 100 points with grade A.

First, I have no knowledge of VC++ at all.
I want to use an ActiveX control (user control) that is developed in VB (Visual Basic), into VC++ (not VC++ .net). Is this possible?
If yes, can anyone give me some sample code (and how to add the control to the project) for using this Smart Print Control ( from http://www.vbgold.com ).
What I need is just to specify the document title and body, and the font name and size and call the PrintDoc method to print the document.
Can anyone help please?

Thank you.
0
BigBoss
Asked:
BigBoss
  • 5
  • 5
1 Solution
 
Svetlin_PanayotovCommented:
Well I'll try to explain it step-by-step:
First - create your VC++ project (MFC Application, Dialog based).Add your ActiveX control to the dialog (right click on the dialog and choose Insert ActiveX control).
Then right click again and select Class Wizard - and go to "Member Variables".In the control ID box select your control ID (probably IDC_SPRINTER1) and click Add variable. Name it m_Printer.
After adding it double click on the OK button in your dialog.There you should have code like:

void CPrintDlg::OnOK()
{
      m_Printer.SetDocText("Your text");
      m_Printer.SetDocTitle("Your title");
      m_Printer.PrintDoc("PrinterName");
}

And...that's all :)

Svetlin
0
 
BigBossAuthor Commented:
Svetlin_Panayotov...thank you for your help.
I did exactly what you said but I couldn't make it to print. Of course I changed the "PrinterName" to a valid one.
When I click on the OK button, nothing gets out of the printer!!
I tried to check if it does something, so I replaced the  m_Printer.PrintDoc("PrinterName");  with  m_Printer.About(); and it does show the About dialog when I click the button!
Did you checked whether it really prints or not in your VC++?
If it works for you, can you send me the project please?

Thank you.
0
 
Svetlin_PanayotovCommented:
Sorry - my mistake here - the method PrintDoc() needs a parameter that's actually your printer's name - so instead
m_Printer.PrintDoc("Printer name");
you should have something like:
      CPrintDialog pr(FALSE);
      CString s = pr.GetDeviceName();
      int iResult = pr.DoModal();
                if (iResult == IDCANCEL)
                       return;
      m_Print.PrintDoc(s);

Svetlin

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
BigBossAuthor Commented:
Thank you Sveltin....but I gave the printer name hardcoded and it didn't print!
I used something like m_Print.PrintDoc("HP Deskjet xxx");
Does this work? or must I use your code?

Thank you.
0
 
BigBossAuthor Commented:
Sorry, I mean m_Printer.PrintDoc("HP Deskjet xxx");
0
 
Svetlin_PanayotovCommented:
Well - hardcoding your printer's name is generally not good idea - so it's better to use CPrintDialog
0
 
BigBossAuthor Commented:
OK...thanks Sveltin.

Sorry, but you didn't answer my previous question!
Did you test the control in your VC and got it to print?
It does not print here!!! :-(
Am I missing something? Or is this control incompatible with VC++?
If you've got it to print, can you send me a sample project please?

Thank you for your help.
0
 
Svetlin_PanayotovCommented:
Yes - I tested it with VC6 and the code I sent you(with CPrintDialog) - and it wokrs fine.Here's the code
again:

void CTestDlg::OnOK()
{
      CPrintDialog pr(FALSE);
      int iResult = pr.DoModal();
      if (iResult == IDCANCEL)
            return;
      CString sPrinterName = pr.GetDeviceName();
      m_Print.SetDocText("Some text");
      m_Print.SetDocTitle("Title");
      m_Print.PrintDoc(sPrinterName);
}

just replace CTestDlg with the name of your dialog - or copy only the code from the method
Svetlin
0
 
BigBossAuthor Commented:
OK...thanks...it worked, but only the second part!

The first part (below) is not working!

     CPrintDialog pr(FALSE);
     int iResult = pr.DoModal();
     if (iResult == IDCANCEL)
          return;
     CString sPrinterName = pr.GetDeviceName();

I was getting errors on compilation!
0
 
Svetlin_PanayotovCommented:
Well, can you please post the errors?
BTW this code works well for me.

Svetlin
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now