Custom dll troubles

G

Guest

Hello everyone. I am trying to create a custom dll to show a message box. I
am running into difficulty when I try to call the custom dll function custom
menuitem. Excel gives the messagebox that it caused a serious error and
needs to close.
I have a partial work around in the custommenu xla in thisworkbook object i
use sendkeys to open and exit the vb editor and tis works great. but if I
open an excel file it seems to halt opening the file after I open and close
the vb editor window.
Any insites about this would be greatly appreciated.
Thanks in advance

In the general declaration section I have the following:
Private Declare Sub message Lib "g:\paul\stringsPart2\string2dll.dll" ()
I call this sub from a sub in a module

The sub is as follows:

Private Sub CHKNet()
message
End Sub

The sub in the custom dll is as follows:

Private Sub message()
MsgBox "Can you read this"
End Sub
 
C

Chip Pearson

You can't create Windows DLLs in VB or VBA. You can only create
ActiveX DLLs. Your ActiveX DLL should have a creatable class that
exposes the properties and methods. Then, you don't use the
Declare statement, but instead use code like

Dim MyClass As MyDLLProject.CreatableClass
Set MyClass = New MyDLLProject.CreatableClass
MyClass.MyProcedure


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
G

Guest

:

"You can't create Windows DLLs in VB or VBA. You can only create ActiveX
DLLs. "

Can you create ActiveX DLLs in VBA?
 
G

Guest

I didn't think you could; however, your turn of phrase implied you could ...
at least my reading of it.
 
G

Guest

I did exactly that. I used that as a template for what I want to do. My
problem is that I can't seem to execute/run the dll code after excel is
loaded. Excel closes unexpectlfy when I try to access sub/functions in the
dll.
 
P

Peter T

I've seen that example and couldn't make it work. Perhaps I didn't get it
right but I recall comments from others who couldn't either.

It's certainly not the normal way of doing things, to quote from the
article -

"
Certainly it's true that out of the box, Visual Basic doesn't allow you to
create a Windows DLL in the same way that you can create other project
types, like a Standard EXE or an ActiveX DLL. In this article, we'll go
exploring to see how Visual Basic generates its executables. In the process,
we'll discover that with a little bit of extra work, we can in fact create
Windows DLLs with Visual Basic.
"

The normal way of course is with an ActiveX dll created in VB (not VBA) and
used along the lines suggested by Chip Pearson earlier in this thread, and
if using Early Binding with a reference set in Tools. A C# dll or xll of
course is different.

Regards,
Peter T
 
G

Guest

I did make it work by by the steps on this page. It works quite nicely. The
only way I can access the dll is start the vb editor and quit then everything
works fine.
Here is the page that I got it to work with. There are somethnings still you
have to do in order to be able to pass strings to and from the dll. I can
compile the dll straight from vba. This is great I just need this little
thing to work and everythting would be great.

http://www.vb-helper.com/howto_make_standard_dll.html
 
P

Peter T

I don't doubt that the examples in the links give by Nick earlier and yours
below can be made to work but you say
I can compile the dll straight from vba.

Surely you don't mean in your Excel VBE without VB (eg Visual Studio), or am
I misunderstanding something. Do you have a bunch of project files including
a *.vbp

If you really have got something almost working, looking at your OP I see
you declare the dll with full path. Try putting it the same folder as your
workbook, trap the current directory (to reset later) and do a ChDir to
your path. That's not even a wild guess, just chucking seeds in the air but
for certain things that's what one might do in VB6.

At the time I was curious about making a Windows dll with VB for use in VBA
but binned it. Perhaps I should look again.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top