![]() |
C++ DLL from VBA
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. |
C++ DLL from VBA
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. |
C++ DLL from VBA
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. |
C++ DLL from VBA
On Aug 23, 7:47 am, Equiangular 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. |
C++ DLL from VBA
On Aug 23, 8:17 am, thekind78 wrote:
On Aug 23, 7:47 am, Equiangular 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. |
C++ DLL from VBA
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 wrote: On Aug 23, 7:47 am, Equiangular 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. |
C++ DLL from VBA
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 wrote: On Aug 23, 7:47 am, Equiangular 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. |
C++ DLL from VBA
On Aug 23, 10:23 am, Equiangular 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 wrote: On Aug 23, 7:47 am, Equiangular 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. |
All times are GMT +1. The time now is 02:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com