ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Custom dll troubles (https://www.excelbanter.com/excel-programming/361494-custom-dll-troubles.html)

Paul

Custom dll troubles
 
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



Chip Pearson

Custom dll troubles
 
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



"Paul" wrote in message
...
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





AA2e72E

Custom dll troubles
 
"Chip Pearson" wrote:

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

Can you create ActiveX DLLs in VBA?

Chip Pearson

Custom dll troubles
 
No.


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


"AA2e72E" wrote in message
...
"Chip Pearson" wrote:

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

Can you create ActiveX DLLs in VBA?




AA2e72E

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

Paul

Custom dll troubles
 
why not? I think I did.

"Chip Pearson" wrote:

No.


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


"AA2e72E" wrote in message
...
"Chip Pearson" wrote:

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

Can you create ActiveX DLLs in VBA?





NickHK

Custom dll troubles
 
Paul,
Unless you followed the steps on
http://www.windowsdevcenter.com/pub/...reate_dll.html
what you have is an ActiveX dll.

NickHK

"Paul" wrote in message
...
why not? I think I did.

"Chip Pearson" wrote:

No.


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


"AA2e72E" wrote in message
...
"Chip Pearson" wrote:

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

Can you create ActiveX DLLs in VBA?







Paul

Custom dll troubles
 
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.

"NickHK" wrote:

Paul,
Unless you followed the steps on
http://www.windowsdevcenter.com/pub/...reate_dll.html
what you have is an ActiveX dll.

NickHK

"Paul" wrote in message
...
why not? I think I did.

"Chip Pearson" wrote:

No.


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


"AA2e72E" wrote in message
...
"Chip Pearson" wrote:

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

Can you create ActiveX DLLs in VBA?







Peter T

Custom dll troubles
 
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

"Paul" wrote in message
...
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.

"NickHK" wrote:

Paul,
Unless you followed the steps on
http://www.windowsdevcenter.com/pub/...reate_dll.html
what you have is an ActiveX dll.

NickHK

"Paul" wrote in message
...
why not? I think I did.

"Chip Pearson" wrote:

No.


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


"AA2e72E" wrote in message
...
"Chip Pearson" wrote:

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

Can you create ActiveX DLLs in VBA?









Paul

Custom dll troubles
 
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

"Peter T" wrote:

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

"Paul" wrote in message
...
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.

"NickHK" wrote:

Paul,
Unless you followed the steps on
http://www.windowsdevcenter.com/pub/...reate_dll.html
what you have is an ActiveX dll.

NickHK

"Paul" wrote in message
...
why not? I think I did.

"Chip Pearson" wrote:

No.


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


"AA2e72E" wrote in message
...
"Chip Pearson" wrote:

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

Can you create ActiveX DLLs in VBA?










Paul

Custom dll troubles
 
Why was it not working. I may be able to help you figure it out if you are
willing.

"Peter T" wrote:

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

"Paul" wrote in message
...
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.

"NickHK" wrote:

Paul,
Unless you followed the steps on
http://www.windowsdevcenter.com/pub/...reate_dll.html
what you have is an ActiveX dll.

NickHK

"Paul" wrote in message
...
why not? I think I did.

"Chip Pearson" wrote:

No.


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


"AA2e72E" wrote in message
...
"Chip Pearson" wrote:

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

Can you create ActiveX DLLs in VBA?










Peter T

Custom dll troubles
 
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

"Paul" wrote in message
...
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

"Peter T" wrote:

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

"Paul" wrote in message
...
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.

"NickHK" wrote:

Paul,
Unless you followed the steps on

http://www.windowsdevcenter.com/pub/...reate_dll.html
what you have is an ActiveX dll.

NickHK

"Paul" wrote in message
...
why not? I think I did.

"Chip Pearson" wrote:

No.


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


"AA2e72E" wrote in message
...
"Chip Pearson" wrote:

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

Can you create ActiveX DLLs in VBA?













All times are GMT +1. The time now is 12:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com