C++ DLL from VBA

T

thekind78

Hello all,
Trying to call a C++ function from VBA. Function is declared as
following in C++:

func(char[],int[],int)

The function reads the char*, does some manipulations on the data
within it, and writes the results to the int*. There are two things I
see as problems:
1) the int values in C++ are greater than the max value permitted in
VBA
2) not sure how to pass the parameters to the dll from VBA

I have been trying some combination of the following:

func(ByRef string, ByRef int(1), ByVal int)
i.e. sending down the address of the string, the address of the
first element of the integer array and the value of an integer which
corresponds to the number of iterations that are required for some
processing done in the C++ code. Can anyone suggest how to address the
two problems above? As it stands now, the code completely shuts down
Excel without even a warning. Some illegal memory addressing I guess
but not sure how to get around it. Thanks in advance.
 
E

Equiangular

One point to add
You should use ByVal for the first and second parameter

The following link is quite useful
http://support.microsoft.com/?scid=kb;en-us;106553&x=16&y=9
use long instead of integer in vba
long is signed 32 bit integer
Hello all,
Trying to call a C++ function from VBA. Function is declared as
following in C++:

func(char[],int[],int)

The function reads the char*, does some manipulations on the data
within it, and writes the results to the int*. There are two things I
see as problems:
1) the int values in C++ are greater than the max value permitted in
VBA
2) not sure how to pass the parameters to the dll from VBA

I have been trying some combination of the following:

func(ByRef string, ByRef int(1), ByVal int)
i.e. sending down the address of the string, the address of the
first element of the integer array and the value of an integer which
corresponds to the number of iterations that are required for some
processing done in the C++ code. Can anyone suggest how to address the
two problems above? As it stands now, the code completely shuts down
Excel without even a warning. Some illegal memory addressing I guess
but not sure how to get around it. Thanks in advance.
 
T

thekind78

One point to add
You should use ByVal for the first and second parameter

The following link is quite usefulhttp://support.microsoft.com/?scid=kb%3Ben-us%3B106553&x=16&y=9


use long instead of integer in vba
long is signed 32 bit integer
thekind78 said:
Hello all,
Trying to call a C++ function from VBA. Function is declared as
following in C++:
func(char[],int[],int)
The function reads the char*, does some manipulations on the data
within it, and writes the results to the int*. There are two things I
see as problems:
1) the int values in C++ are greater than the max value permitted in
VBA
2) not sure how to pass the parameters to the dll from VBA
I have been trying some combination of the following:
func(ByRef string, ByRef int(1), ByVal int)
i.e. sending down the address of the string, the address of the
first element of the integer array and the value of an integer which
corresponds to the number of iterations that are required for some
processing done in the C++ code. Can anyone suggest how to address the
two problems above? As it stands now, the code completely shuts down
Excel without even a warning. Some illegal memory addressing I guess
but not sure how to get around it. Thanks in advance.- Hide quoted text -

- Show quoted text -

Equiangular,
Thanks for your help. I'm still getting a Segmentation fault of sorts
as Excel just shuts down. Is it necessary to register the dll before
using it? Thank you.
 
T

thekind78

One point to add
You should use ByVal for the first and second parameter
The following link is quite usefulhttp://support.microsoft.com/?scid=kb%3Ben-us%3B106553&x=16&y=9
Equiangular said:
use long instead of integer in vba
long is signed 32 bit integer
thekind78 wrote:
Hello all,
Trying to call a C++ function from VBA. Function is declared as
following in C++:
func(char[],int[],int)
The function reads the char*, does some manipulations on the data
within it, and writes the results to the int*. There are two things I
see as problems:
1) the int values in C++ are greater than the max value permitted in
VBA
2) not sure how to pass the parameters to the dll from VBA
I have been trying some combination of the following:
func(ByRef string, ByRef int(1), ByVal int)
i.e. sending down the address of the string, the address of the
first element of the integer array and the value of an integer which
corresponds to the number of iterations that are required for some
processing done in the C++ code. Can anyone suggest how to address the
two problems above? As it stands now, the code completely shuts down
Excel without even a warning. Some illegal memory addressing I guess
but not sure how to get around it. Thanks in advance.- Hide quoted text -
- Show quoted text -

Equiangular,
Thanks for your help. I'm still getting a Segmentation fault of sorts
as Excel just shuts down. Is it necessary to register the dll before
using it? Thank you.- Hide quoted text -

- Show quoted text -

Also,
Is it necessary for the DLL to include a LibMain function? It
contains a DllEntryPoint function. Thanks for your help.
 
E

Equiangular

Hi

I'm sorry that I'm not familiar with c++ DLL. For "traditional" DLL (I
mean not activeX DLL), there is no need to register. Just call in a
similar way like windows API.

Some correction to make, the second parameter should be byref as this is
an array.
One point to add
You should use ByVal for the first and second parameter
The following link is quite usefulhttp://support.microsoft.com/?scid=kb%3Ben-us%3B106553&x=16&y=9
Equiangular wrote:
use long instead of integer in vba
long is signed 32 bit integer
thekind78 wrote:
Hello all,
Trying to call a C++ function from VBA. Function is declared as
following in C++:
func(char[],int[],int)
The function reads the char*, does some manipulations on the data
within it, and writes the results to the int*. There are two things I
see as problems:
1) the int values in C++ are greater than the max value permitted in
VBA
2) not sure how to pass the parameters to the dll from VBA
I have been trying some combination of the following:
func(ByRef string, ByRef int(1), ByVal int)
i.e. sending down the address of the string, the address of the
first element of the integer array and the value of an integer which
corresponds to the number of iterations that are required for some
processing done in the C++ code. Can anyone suggest how to address the
two problems above? As it stands now, the code completely shuts down
Excel without even a warning. Some illegal memory addressing I guess
but not sure how to get around it. Thanks in advance.- Hide quoted text -
- Show quoted text -
Equiangular,
Thanks for your help. I'm still getting a Segmentation fault of sorts
as Excel just shuts down. Is it necessary to register the dll before
using it? Thank you.- Hide quoted text -

- Show quoted text -

Also,
Is it necessary for the DLL to include a LibMain function? It
contains a DllEntryPoint function. Thanks for your help.
 
E

Equiangular

The following URL gives a step by step example

www.che.utexas.edu/cache/newsletters/spring2001_useofc.pdf

Hope it's useful to you
One point to add
You should use ByVal for the first and second parameter
The following link is quite usefulhttp://support.microsoft.com/?scid=kb%3Ben-us%3B106553&x=16&y=9
Equiangular wrote:
use long instead of integer in vba
long is signed 32 bit integer
thekind78 wrote:
Hello all,
Trying to call a C++ function from VBA. Function is declared as
following in C++:
func(char[],int[],int)
The function reads the char*, does some manipulations on the data
within it, and writes the results to the int*. There are two things I
see as problems:
1) the int values in C++ are greater than the max value permitted in
VBA
2) not sure how to pass the parameters to the dll from VBA
I have been trying some combination of the following:
func(ByRef string, ByRef int(1), ByVal int)
i.e. sending down the address of the string, the address of the
first element of the integer array and the value of an integer which
corresponds to the number of iterations that are required for some
processing done in the C++ code. Can anyone suggest how to address the
two problems above? As it stands now, the code completely shuts down
Excel without even a warning. Some illegal memory addressing I guess
but not sure how to get around it. Thanks in advance.- Hide quoted text -
- Show quoted text -
Equiangular,
Thanks for your help. I'm still getting a Segmentation fault of sorts
as Excel just shuts down. Is it necessary to register the dll before
using it? Thank you.- Hide quoted text -

- Show quoted text -

Also,
Is it necessary for the DLL to include a LibMain function? It
contains a DllEntryPoint function. Thanks for your help.
 
T

thekind78

The following URL gives a step by step example

www.che.utexas.edu/cache/newsletters/spring2001_useofc.pdf

Hope it's useful to you


One point to add
You should use ByVal for the first and second parameter
The following link is quite usefulhttp://support.microsoft.com/?scid=kb%3Ben-us%3B106553&x=16&y=9
Equiangular wrote:
use long instead of integer in vba
long is signed 32 bit integer
thekind78 wrote:
Hello all,
Trying to call a C++ function from VBA. Function is declared as
following in C++:
func(char[],int[],int)
The function reads the char*, does some manipulations on the data
within it, and writes the results to the int*. There are two things I
see as problems:
1) the int values in C++ are greater than the max value permitted in
VBA
2) not sure how to pass the parameters to the dll from VBA
I have been trying some combination of the following:
func(ByRef string, ByRef int(1), ByVal int)
i.e. sending down the address of the string, the address of the
first element of the integer array and the value of an integer which
corresponds to the number of iterations that are required for some
processing done in the C++ code. Can anyone suggest how to address the
two problems above? As it stands now, the code completely shuts down
Excel without even a warning. Some illegal memory addressing I guess
but not sure how to get around it. Thanks in advance.- Hide quoted text -
- Show quoted text -
Equiangular,
Thanks for your help. I'm still getting a Segmentation fault of sorts
as Excel just shuts down. Is it necessary to register the dll before
using it? Thank you.- Hide quoted text -
- Show quoted text -
Also,
Is it necessary for the DLL to include a LibMain function? It
contains a DllEntryPoint function. Thanks for your help.- Hide quoted text -

- Show quoted text -

Equiangular,
Thanks for your help.
 

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