PC Review


Reply
Thread Tools Rate Thread

C++ DLL from VBA

 
 
thekind78
Guest
Posts: n/a
 
      22nd Aug 2007
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.

 
Reply With Quote
 
 
 
 
Equiangular
Guest
Posts: n/a
 
      23rd Aug 2007
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.
>

 
Reply With Quote
 
Equiangular
Guest
Posts: n/a
 
      23rd Aug 2007
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=k...06553&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.
>>

 
Reply With Quote
 
thekind78
Guest
Posts: n/a
 
      23rd Aug 2007
On Aug 23, 7:47 am, Equiangular <equiangu...@hotmail.com> wrote:
> 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.

 
Reply With Quote
 
thekind78
Guest
Posts: n/a
 
      23rd Aug 2007
On Aug 23, 8:17 am, thekind78 <vijayvadlam...@hotmail.com> wrote:
> On Aug 23, 7:47 am, Equiangular <equiangu...@hotmail.com> wrote:
>
>
>
>
>
> > 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.

 
Reply With Quote
 
Equiangular
Guest
Posts: n/a
 
      23rd Aug 2007
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.

thekind78 wrote:
> On Aug 23, 8:17 am, thekind78 <vijayvadlam...@hotmail.com> wrote:
>> On Aug 23, 7:47 am, Equiangular <equiangu...@hotmail.com> wrote:
>>
>>
>>
>>
>>
>>> 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.
>

 
Reply With Quote
 
Equiangular
Guest
Posts: n/a
 
      23rd Aug 2007
The following URL gives a step by step example

http://www.che.utexas.edu/cache/news...001_useofc.pdf

Hope it's useful to you

thekind78 wrote:
> On Aug 23, 8:17 am, thekind78 <vijayvadlam...@hotmail.com> wrote:
>> On Aug 23, 7:47 am, Equiangular <equiangu...@hotmail.com> wrote:
>>
>>
>>
>>
>>
>>> 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.
>

 
Reply With Quote
 
thekind78
Guest
Posts: n/a
 
      27th Aug 2007
On Aug 23, 10:23 am, Equiangular <equiangu...@hotmail.com> wrote:
> The following URL gives a step by step example
>
> http://www.che.utexas.edu/cache/news...001_useofc.pdf
>
> Hope it's useful to you
>
>
>
> thekind78 wrote:
> > On Aug 23, 8:17 am, thekind78 <vijayvadlam...@hotmail.com> wrote:
> >> On Aug 23, 7:47 am, Equiangular <equiangu...@hotmail.com> wrote:

>
> >>> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:31 AM.