Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: unsigned long - VB6 Добавлено: 29.04.04 13:34  

Автор вопроса:  SHDZ | ICQ: 209382104 

Как уже и говорил, есть ActiveX DLL, в ней функция, входные данные - unsigned long

это уже сам увидел в С-шном виевере, так вот VB не хочет определять этот тип данных,

как можно воспользоваться этой функцией:

[id(0x60020013)]

int RegistrItem(

[in] BSTR Name,

[in] unsigned long ulSum,

[in] unsigned long ulPrice,

[in] unsigned long ulQnty,

[in] int iWeight,

[in] long lDiscount);

Ответить

  Ответы Всего ответов: 5  

Номер ответа: 1
Автор ответа:
 LamerOnLine



ICQ: 334781088 

Вопросов: 108
Ответов: 2822
 Профиль | | #1 Добавлено: 30.04.04 08:48

Пардон, поста не заметил, отписал на старый...

Меня тоже этот вопрос заинтересовал. Уж и не знаю как сделать.

Была мысль сделать классик dll на с++, в которую импортировать этот ActiveX. Бредово, конечно, но, думаю, альтернативы будут еще замороченей.

Ответить

Номер ответа: 2
Автор ответа:
 SHDZ



ICQ: 209382104 

Вопросов: 39
Ответов: 244
 Профиль | | #2 Добавлено: 30.04.04 12:52

Да, спасиба, мысли сошлись.

Только я на С++ очень слабо, как подключить в ДЛЛ ActiveX DLL?

Ответить

Номер ответа: 3
Автор ответа:
 LamerOnLine



ICQ: 334781088 

Вопросов: 108
Ответов: 2822
 Профиль | | #3 Добавлено: 30.04.04 13:01

Уверен что вставится коряво, но все же попробую...

Knowledge Base Articles

HOWTO: Access a Visual Basic ActiveX DLL from Visual C++

Q194873

--------------------------------------------------------------------------------

The information in this article applies to:

Microsoft Visual C++, 32-bit Enterprise Edition, versions 5.0, 6.0

Microsoft Visual C++, 32-bit Professional Edition, versions 5.0, 6.0

Microsoft Visual C++, 32-bit Learning Edition, version 6.0

--------------------------------------------------------------------------------

SUMMARY

This article shows three ways to access a Visual Basic ActiveX DLL from a Visual C++ 6.0 executable.

MORE INFORMATION

This article represents an introduction to creating Visual C++ clients for Visual Basic ActiveX components. If you are already proficient with Visual C++, you may wish to refer to the reference section for a list of more advanced topics.

Steps to Create the Visual Basic Server

Create a Visual Basic ActiveX DLL project. Class1 is created by default.

Add the following code to Class1:

Public Function MyVBFunction(x As Integer) As Integer

MsgBox x

End Function

Compile the DLL as c:\Project1.dll and exit Visual Basic.

Method 1 - CreateDispatch:

Start Visual C++ and select New on the File menu. Choose MFC AppWizard (Exe) and a project name, and Click OK. When the MFC AppWizard dialog box appears, click Finish. Click OK on the next dialog box.

Select ClassWizard on the View menu, pick Ctst1App in the Class Name box, and double-click InitInstance in the Messages box. Click Edit Code to bring up the code for BOOL CTst1App::InitInstance(), find the line AfxEnableControlContainer();, and add the following line before it:

AfxOleInit();

Select ClassWizard from the View menu and click the Automation tab. Click AddClass and select "from a TypeLibrary". Specify Project1.dll, the Visual Basic DLL which was created in step 3. When the Confirm Classes dialog box appears, click OK. Click OK again to close the MFC ClassWizard dialog box.

Open your .cpp file and add the line #include "Project1.h". You need to include Project1.h wherever you have code that accesses project1.dll.

Open the ClassWizard again. On the Message Maps tab, select CAboutDlg in the Class Name box and IDOK in the Object IDs box, and then double-click BN_CLICKED. Click OK in response to the dialog box and OK again to close the ClassWizard.

Open .cpp, scroll to the bottom to theCAboutDlg::OnOK(), and replace it with the following code:

void CAboutDlg::OnOK()

{

short st = 2;

short st1;

_Class1 p;

p.CreateDispatch("Project1.Class1");

st1 = p.MyVBFunction(&st);

CDialog::OnOK();

}

Compile your .exe file (F7).

Run the .exe file and select About on the Help menu. Click OK on the About box and the message box that was specified in project1.dll appears. Click the Close button to dismiss the dialog box.

Method 2 - #IMPORT:

Start Visual C++ 6.0 and create a Win32 Console Application. Select "An Empty Project" and click Finish.

Point to Add to Project on the Project menu and click New to add a new C++ source file to the project. Paste the following code in the new source file and save it:

#include

// This is the path for your DLL.

// Make sure that you specify the exact path.

#import "c:\project1.dll" no_namespace

void main()

{

BSTR bstrDesc;

try

{

CoInitialize(NULL);

short st = 2;

short st1;

// Declare the Interface Pointer for your Visual Basic object. Here,

// _Class1Ptr is the Smart pointer wrapper class representing the

// default interface of the Visual Basic object.

_Class1Ptr ptr;

// Create an instance of your Visual Basic object, here

// __uuidof(Class1) gets the CLSID of your Visual Basic object.

ptr.CreateInstance(__uuidof(Class1));

st1 = ptr->MyVBFunction(&st);

}

catch(_com_error &e)

{

bstrDesc = e.Description();

}

CoUninitialize();

}

Compile and run your project. The message box from Project1.DLL should appear.

The #import method can be used in a Win32 Application, a Console Application, or in MFC as well.

Method 3 - Pure COM Interface

Start Visual C++ and select New from the File menu. Choose MFC AppWizard (Exe), name the project tst1, and click OK. When the MFC Appwizard dialog box appears, select Dialog Based and click Finish. Click OK when the next dialog box appears.

The Resource Editor is started by default. Delete all the controls on the dialog box and add a Command button on it, retaining the default caption "Button1".

Double-click Button1 to display the Add Member Function dialog box. Click OK to accept the name OnButton1.

Click OLE/COM Object Viewer on the Tools menu. Select View Typelib from the File menu and choose the Project1.dll you created earlier. Click Open to display the ITypeLib Viewer, which contains the .idl file for your DLL.

Copy the contents of your .idl file (contents of the right pane) to the Clipboard. Hold the SHIFT key down while paging or scrolling from the first character to the end of the text in the pane. Press Ctrl+C to copy the marked text to the Clipboard.

Click New on Visual C++ File menu. Select Text File on the New dialog box, name the file test1.idl, and click OK.

A blank text file appears. Paste the data from the Clipboard into it and save the file.

Select Settings from the Project menu, expand the tst1 and Source Files nodes of the tree view, and select test1.idl. Click the MIDL tab, enter test1.h in the "Output header file name" box, and click OK.

Open tst1Dlg.cpp and add the following files to the

Ответить

Номер ответа: 4
Автор ответа:
 SHDZ



ICQ: 209382104 

Вопросов: 39
Ответов: 244
 Профиль | | #4 Добавлено: 30.04.04 13:08

Спасиба!!!!!

Ответить

Номер ответа: 5
Автор ответа:
 LamerOnLine



ICQ: 334781088 

Вопросов: 108
Ответов: 2822
 Профиль | | #5 Добавлено: 30.04.04 14:31

Пожалуйста, но вопрос не снят. Если есть идеи как запустить метод из ActiveX Dll как классик функцию - ПИШИТЕ!

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам