Convert C++ to VB.Net

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 3
Reputation: TheRoyalFalcon is an unknown quantity at this point 
Solved Threads: 0
TheRoyalFalcon TheRoyalFalcon is offline Offline
Newbie Poster

Convert C++ to VB.Net

 
0
  #1
Sep 4th, 2007
I found some code on the web a while back. But I don't know who wrote it.

The code below looks for worksheet names in a excel file. I am not familiar with C++ (and do little to nothing with binary files). Can someone help me convert the code below from C++ to VB.net? Thank you in advance.

trf

  1. IStorage *pStorage = 0;
  2. HRESULT hResult = ::StgOpenStorage(L"C:\\MyExcel.xls", NULL, STGM_READ |STGM_SHARE_DENY_WRITE, NULL, 0, &pStorage);
  3. IStream *pStream = 0;
  4. hResult = pStorage->OpenStream(L"Workbook", NULL, STGM_READ |STGM_SHARE_EXCLUSIVE, 0, &pStream);
  5. char buf[32000]; DWORD dwRead = 0; short id = 0, len = 0;
  6. while (1) {
  7. hResult = pStream->Read(&id, 2, &dwRead);
  8. if( (FAILED(hResult)) || (dwRead != 2) ) break;
  9. hResult = pStream->Read(&len, 2, &dwRead);
  10. if( (FAILED(hResult)) || dwRead != 2 || ((id == 0) && (len == 0)) ) break;
  11. if( (id & 0x00FF) == 0x85 ) {
  12. pStream->Read(buf, len, &dwRead);
  13. buf[len] = 0;
  14. cout << buf+8 << endl;
  15. continue;
  16. }
  17. if(len > sizeof(buf)) len = sizeof(buf);
  18. pStream->Read(buf, (long)len, &dwRead);
  19. if((DWORD)len != dwRead) break;
  20. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: Convert C++ to VB.Net

 
0
  #2
Sep 4th, 2007
You should forget about converting C++ to VB.NET and look for something originally in .NET. It's a lot easier to use the excel library or ADO.NET than to hack the file format as a binary stream. There are a lot of threads on reading and writing excel on the vb.net forum, go check those out.
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 3
Reputation: TheRoyalFalcon is an unknown quantity at this point 
Solved Threads: 0
TheRoyalFalcon TheRoyalFalcon is offline Offline
Newbie Poster

Re: Convert C++ to VB.Net

 
0
  #3
Sep 4th, 2007
Sorry in advance for the length.

I hear you here. I find myself in a tight spot and there isn’t much I can do. I use the .Net Report Viewer control to render Excel 97 Biff8 files. Rendering is a nice side feature of the control (the main being report viewing). I need to create Biff8 files from code running on a server. Since my code runs on a server, Excel automation is out (too many instances of it will need to run and it will crash). I could look a buying something but my employer isn’t big on that. Besides I have something working perfectly. Perfectly that is except the output doesn’t have the gridlines on. Its true BIFF8 (which is a requirement) but with the gridlines off there has been too much confusion from the LOB. So I’ve been told, get those grids on.

I’ve looked off-and-on for weeks for a solution, but have found nothing. All I could think to do at this point was to pull a document explaining the file format (http://sc.openoffice.org/excelfileformat.pdf) and try to write the updates to the files myself. It didn’t sound too bad until I tried it (ha).

So then I read up on the Biff8 for Excel, found it was an OLE2 Binary file, and went looking for anything related to updating that. Surprisingly I found some C++ articles at least talking about it. Then I found this, which appears to read through an Excel file. I figured this was at least a start.

Anyway given a more detailed explanation of my situation and why I find myself needing to reverse engineer the above C++ example, do you think anyone might be able to help me here? In the interim I’m using ADO to create basic XLS files but I will only be able to get by on that so long.

Thanks for any ideas.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 32
Reputation: VatooVatoo is an unknown quantity at this point 
Solved Threads: 2
VatooVatoo's Avatar
VatooVatoo VatooVatoo is offline Offline
Light Poster

Re: Convert C++ to VB.Net

 
0
  #4
Sep 5th, 2007
You can buid a DLL and call from your .NET program.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 13
Reputation: Ixeman is an unknown quantity at this point 
Solved Threads: 0
Ixeman Ixeman is offline Offline
Newbie Poster

Re: Convert C++ to VB.Net

 
0
  #5
Oct 27th, 2008
Edit: removed
Last edited by Ixeman; Oct 27th, 2008 at 10:52 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC