Click here to Skip to main content
15,896,118 members
Home / Discussions / COM
   

COM

 
GeneralRe: COM Interop C++ unmanaged through C# .NET 2.0 Class Library to C# .NET 1.1managed Class Library Pin
Scott Dorman10-Mar-08 15:49
professionalScott Dorman10-Mar-08 15:49 
Generalusing com without registration Pin
justintimberlake8-Mar-08 16:31
justintimberlake8-Mar-08 16:31 
GeneralRe: using com without registration Pin
User 2155979-Mar-08 3:14
User 2155979-Mar-08 3:14 
GeneralRe: using com without registration Pin
justintimberlake9-Mar-08 16:52
justintimberlake9-Mar-08 16:52 
GeneralRe: using com without registration Pin
User 21559710-Mar-08 11:32
User 21559710-Mar-08 11:32 
GeneralProxy Manager on Remote Clients Pin
swjam7-Mar-08 22:04
swjam7-Mar-08 22:04 
GeneralEvent Map of an ActiveX control Pin
AbbyIndian6-Mar-08 6:59
AbbyIndian6-Mar-08 6:59 
QuestionCOM Addin crashes Excel. What am I doing wrong? Pin
ssaddi3-Mar-08 19:35
ssaddi3-Mar-08 19:35 
Hi,

I tried the (provided) code as part of an AddIn for Excel. I am able to call the function and also pass data to it. However, midway through the processing Excel crashes. I use the default way to debug the application i.e. when it crashes I click on Debug and use the Visual Studio IDE to debug the application.

NOTE: Please bear in mind that I have almost no experience with Visual C++ and very little experience with C++. I have tried to build upon some code that was handed over to me and have succeeded in passing non-array variables from Excel to COM and performing operations and successfully returning values. I have started facing problems while passing and returning arrays.

I get the error: Unhandled exception at 0x77c47fd4 in EXCEL.EXE: 0xC00000005: Access violation reading location 0x00000008.

CODE:

<br />
STDMETHODIMP CAddin::TEST(VARIANT input, VARIANT* output)<br />
{<br />
   LONG lstart, lend;<br />
   LONG idx = -1;<br />
   LONG nPOS;<br />
   HRESULT hr;<br />
   BSTR HUGEP* pbstr;<br />
   pbstr[input.parray->rgsabound->cElements];<br />
   std::list holder;<br />
   SAFEARRAY *sa = V_ARRAY(&input);<br />
   hr=SafeArrayGetLBound(sa,1,&lstart);<br />
   if (FAILED(hr)) return hr;<br />
   hr=SafeArrayGetUBound(sa,1,&lend);<br />
   if (FAILED(hr)) return hr;<br />
   LOG_DEBUG(lstart<<" "<<lend<<std::endl);<br />
   USES_CONVERSION;<br />
   hr=SafeArrayAccessData(sa,(void HUGEP* FAR*)&pbstr);<br />
   LOG_DEBUG("PBSTR "<<pbstr<<" "<<*pbstr<<std::endl);<br />
   if (SUCCEEDED(hr)){<br />
     for (idx=lstart;idx<=lend;idx++){<br />
        CComBSTR s;<br />
        LOG_DEBUG(idx<<" "<<pbstr[idx]<<std::endl);<br />
        holder.push_back(W2A(s.m_str));<br />
     }<br />
     hr=SafeArrayUnaccessData(sa);<br />
     if (FAILED(hr)) return hr;<br />
     for (int i=0;i<holder.size();i++){><br />
        LOG_DEBUG("Vals "<<holder.front()<<std::endl);<br />
        holder.pop_front();<br />
     }<br />
    }<br />
    else<br />
        return hr;<br />
}<br />
</holder.size();i++){>


The LOG_DEBUG (...) function simply prints stuff into a log file.

From the debug session, it looks like the value for pbstr is ok, it is 06BAE7E8 but the value stored at that location is not good, it is 0x00000008 which is an inaccessible location address. Does this mean that the SafeArrayAccessData is not providing me with the correct memory addresses? BTW, the bounds of the passed array are good and so is the data in the safearray as I have found out from the debug session.

When I debug the crash, I get to see the following code:

<br />
CComBSTR& operator=(__in_opt LPOLESTR pSrc)<br />
{<br />
   if (pSrc != m_str){<br />
      ::SysFreeString(m_str);<br />
      if (pSrc != NULL){<br />
         m_str = ::SysAllocString(pSrc);<br />
         if (!*this)<br />
         {<br />
             AtlThrow(E_OUTOFMEMORY);<br />
         }<br />
      }else{<br />
         m_str = NULL;<br />
    }<br />
     return *this;<br />
}<br />


The value for pSrc us 0x00000008<bad_ptr> and the value for m_str is 0x00000000<bad_ptr>.

Some questions:
1. Why am I getting an inaccessible location address?
2. Why do we use HUGEP* and FAR* instead of a simple **? I was using ** earlier but in my efforts to make this work, picked these up from some googled doc/articles online.
3. HOW can I paste stuff into this textbox? I had to rewrite all the code and it has also lost its indentation?

Thanks for any help in this matter. I assure you all, that once I get this working I'd get over this mental block about Visual C++. I want to know what is it that I am doing wrong here...

Cheers
Sukant

P.S. Again, please note that I have just begun my journey of COM/VisualC++/C++, so I would really appreciate any pointers (or FAR* for that matter) on this issue. Any criticism and feedback is more than welcome.
GeneralRe: COM Addin crashes Excel. What am I doing wrong? Pin
Nathan Holt at EMOM4-Mar-08 9:42
Nathan Holt at EMOM4-Mar-08 9:42 
GeneralRe: COM Addin crashes Excel. What am I doing wrong? Pin
ssaddi4-Mar-08 10:58
ssaddi4-Mar-08 10:58 
GeneralRe: COM Addin crashes Excel. What am I doing wrong? Pin
Nathan Holt at EMOM4-Mar-08 11:15
Nathan Holt at EMOM4-Mar-08 11:15 
QuestionRe: COM Addin crashes Excel. What am I doing wrong? Pin
Nathan Holt at EMOM6-Mar-08 4:45
Nathan Holt at EMOM6-Mar-08 4:45 
GeneralRe: COM Addin crashes Excel. What am I doing wrong? Pin
ssaddi6-Mar-08 10:15
ssaddi6-Mar-08 10:15 
GeneralRe: COM Addin crashes Excel. What am I doing wrong? Pin
Nathan Holt at EMOM6-Mar-08 10:43
Nathan Holt at EMOM6-Mar-08 10:43 
GeneralRe: COM Addin crashes Excel. What am I doing wrong? Pin
ssaddi6-Mar-08 10:38
ssaddi6-Mar-08 10:38 
GeneralRe: COM Addin crashes Excel. What am I doing wrong? Pin
Nathan Holt at EMOM6-Mar-08 10:54
Nathan Holt at EMOM6-Mar-08 10:54 
Generalcom dll and console client......... Pin
bhogavalli2-Mar-08 19:52
bhogavalli2-Mar-08 19:52 
GeneralCOM dll connect to console client Pin
sheshidar2-Mar-08 19:19
sheshidar2-Mar-08 19:19 
QuestionRe: COM dll connect to console client Pin
CPallini2-Mar-08 21:04
mveCPallini2-Mar-08 21:04 
GeneralError on this dll file ( LpiCom_6_0.LPOrderPart ) Pin
Sujit Gupta29-Feb-08 23:01
Sujit Gupta29-Feb-08 23:01 
GeneralRe: Error on this dll file ( LpiCom_6_0.LPOrderPart ) Pin
User 2155971-Mar-08 2:06
User 2155971-Mar-08 2:06 
Generalproblem with a WebBrowser control Pin
sashka29-Feb-08 2:06
sashka29-Feb-08 2:06 
GeneralRe: problem with a WebBrowser control Pin
User 2155971-Mar-08 2:08
User 2155971-Mar-08 2:08 
GeneralRe: problem with a WebBrowser control Pin
sashka3-Mar-08 1:12
sashka3-Mar-08 1:12 
GeneralRe: problem with a WebBrowser control Pin
User 2155976-Mar-08 12:35
User 2155976-Mar-08 12:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.