473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

need help in Vc++

1
Hai....



i have Vc++ code . i need to create Dll file by using following code
can u help me....here with this i had sent my vc++ code
Expand|Select|Wrap|Line Numbers
  1. VARIANT root[64] = {0}; // Generic IDispatchs
  2.     VARIANT parm[64] = {0}; // Generic Parameters
  3.     VARIANT rVal = {0}; // Temporary result holder
  4.     int level=0; // Current index into root[]
  5.  
  6.     // Initialize the OLE Library...
  7.     OleInitialize(NULL);
  8.  
  9.     // Line 1: dim app as object 
  10.     VARIANT app = {0};
  11.  
  12.     // Line 2: set app = createobject Excel.Application 
  13.     {
  14.         CLSID clsid;
  15.         CLSIDFromProgID(L"Excel.Application", &clsid);
  16.         HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER, IID_IDispatch, (void **)&rVal.pdispVal);
  17.         if(FAILED(hr)) {
  18.             char buf[256];
  19.             sprintf(buf, "CoCreateInstance() for \"Excel.Application\" failed. Err=%08lx", hr);
  20.             ::MessageBox(NULL, buf, "Error", 0x10010);
  21.             _exit(0);
  22.         }
  23.         rVal.vt = VT_DISPATCH;
  24.     }
  25.     VariantCopy(&app, &rVal);
  26.     VariantClear(&rVal);
  27.  
  28.     // Line 3: app . visible = 1 
  29.     rVal.vt = VT_I4;
  30.     rVal.lVal = 1;
  31.     VariantCopy(&root[++level], &app);
  32.     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal, L"visible", 1, rVal);
  33.     VariantClear(&root[level--]);
  34.     VariantClear(&rVal);
  35.  
  36.     // Line 4: app . workbooks . add 
  37.     VariantCopy(&root[++level], &app);
  38.     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1], root[level++].pdispVal, L"workbooks", 0);
  39.     AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"add", 0);
  40.     VariantClear(&root[level--]);
  41.     VariantClear(&root[level--]);
  42.  
  43.     // Line 5: MsgBox Slow fill example... 
  44.     ::MessageBox(NULL, "Slow fill example...", "MsgBox", MB_SETFOREGROUND);
  45.  
  46.     // Line 6: dim i as long 
  47.     VARIANT i = {0};
  48.  
  49.     // Line 7: dim j as long 
  50.     VARIANT j = {0};
  51.  
  52.     // Line 8: with app . activesheet 
  53.     VariantCopy(&root[++level], &app);
  54.     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal, root[level].pdispVal, L"activesheet", 0);
  55.     VariantClear(&root[level--]);
  56.     VariantCopy(&root[++level], &rVal);
  57.     VariantClear(&rVal);
  58.  
  59.     // Line 9: for i = 1 to 15 
  60.     {
  61.         long endVali = 15;
  62.         i.vt = VT_I4;
  63.         for(i.lVal=1; i.lVal<=endVali; i.lVal++) {
  64.  
  65.             // Line 10: for j = 1 to 15 
  66.             {
  67.                 long endValj = 15;
  68.                 j.vt = VT_I4;
  69.                 for(j.lVal=1; j.lVal<=endValj; j.lVal++) {
  70.  
  71.                     // Line 11: . cells i , j . value = i 
  72.                     VariantCopy(&rVal, &i);
  73.                     VariantCopy(&parm[0], &i);
  74.                     VariantCopy(&parm[1], &j);
  75.                     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1], root[level++].pdispVal, L"cells", 2, parm[1], parm[0]);
  76.                     VariantClear(&parm[0]);
  77.                     VariantClear(&parm[1]);
  78.                     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal, L"value", 1, rVal);
  79.                     VariantClear(&root[level--]);
  80.                     VariantClear(&rVal);
  81.  
  82.                     // Line 12: DoEvents 
  83.                     {
  84.                         MSG msg;
  85.                         while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {
  86.                             TranslateMessage(&msg);
  87.                             DispatchMessage(&msg);
  88.                         }
  89.                     }
  90.  
  91.                     // Line 13: next j 
  92.                 }
  93.             }
  94.  
  95.             // Line 14: next i 
  96.         }
  97.     }
  98.  
  99.     // Line 15: msgbox Click me to clear range 
  100.     ::MessageBox(NULL, "Click me to clear range", "MsgBox", MB_SETFOREGROUND);
  101.  
  102.     // Line 16: . range A1:O15 . Clear 
  103.     parm[0].vt = VT_BSTR; parm[0].bstrVal = ::SysAllocString(L"A1:O15");
  104.     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1], root[level++].pdispVal, L"range", 1, parm[0]);
  105.     VariantClear(&parm[0]);
  106.     AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"Clear", 0);
  107.     VariantClear(&root[level--]);
  108.  
  109.     // Line 17: end with 
  110.     VariantClear(&root[level--]);
  111.  
  112.     // Line 18: msgbox Now the fast way! 
  113.     ::MessageBox(NULL, "Now the fast way!", "MsgBox", MB_SETFOREGROUND);
  114.  
  115.     // Line 19: dim arr 1 to 15 , 1 to 15 as long 
  116.     VARIANT arr;
  117.     arr.vt = VT_ARRAY | VT_VARIANT;
  118.     {
  119.         SAFEARRAYBOUND sab[2];
  120.         sab[0].lLbound = 1; sab[0].cElements = 15-1+1;
  121.         sab[1].lLbound = 1; sab[1].cElements = 15-1+1;
  122.         arr.parray = SafeArrayCreate(VT_VARIANT, 2, sab);
  123.     }
  124.  
  125.     // Line 20: for i = 1 to 15 
  126.     {
  127.         long endVali = 15;
  128.         i.vt = VT_I4;
  129.         for(i.lVal=1; i.lVal<=endVali; i.lVal++) {
  130.  
  131.             // Line 21: for j = 1 to 15 
  132.             {
  133.                 long endValj = 15;
  134.                 j.vt = VT_I4;
  135.                 for(j.lVal=1; j.lVal<=endValj; j.lVal++) {
  136.  
  137.                     // Line 22: arr i , j = i 
  138.                     VariantCopy(&rVal, &i);
  139.                     {
  140.                         VARIANT tmp = {0};
  141.                         long indices[] = {i.lVal,j.lVal};
  142.                         VariantCopy(&tmp, &rVal);
  143.                         SafeArrayPutElement(arr.parray, indices, (void*)&tmp);
  144.                     }
  145.                     VariantClear(&rVal);
  146.  
  147.                     // Line 23: next j 
  148.                 }
  149.             }
  150.  
  151.             // Line 24: next i 
  152.         }
  153.     }
  154.  
  155.     // Line 25: app . activesheet . range A1:O15 . value = arr 
  156.     VariantCopy(&rVal, &arr);
  157.     VariantCopy(&root[++level], &app);
  158.     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1], root[level++].pdispVal, L"activesheet", 0);
  159.     parm[0].vt = VT_BSTR; parm[0].bstrVal = ::SysAllocString(L"A1:O15");
  160.     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1], root[level++].pdispVal, L"range", 1, parm[0]);
  161.     VariantClear(&parm[0]);
  162.     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal, L"value", 1, rVal);
  163.     VariantClear(&root[level--]);
  164.     VariantClear(&root[level--]);
  165.     VariantClear(&root[level--]);
  166.     VariantClear(&rVal);
  167.  
  168.     // Line 26: msgbox All done. 
  169.     ::MessageBox(NULL, "All done.", "MsgBox", MB_SETFOREGROUND);
  170.  
  171.     // Line 27: app . activeworkbook . saved = 1 
  172.     rVal.vt = VT_I4;
  173.     rVal.lVal = 1;
  174.     VariantCopy(&root[++level], &app);
  175.     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1], root[level++].pdispVal, L"activeworkbook", 0);
  176.     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal, L"saved", 1, rVal);
  177.     VariantClear(&root[level--]);
  178.     VariantClear(&root[level--]);
  179.     VariantClear(&rVal);
  180.  
  181.     // Line 28: app . quit 
  182.     VariantCopy(&root[++level], &app);
  183.     AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"quit", 0);
  184.     VariantClear(&root[level--]);
  185.  
  186.     // Line 29: set app = nothing 
  187.     VariantClear(&app);
  188.  
  189.     // Clearing variables
  190.     VariantClear(&app);
  191.     VariantClear(&i);
  192.     VariantClear(&j);
  193.     VariantClear(&arr);
  194.  
  195.     // Close the OLE Library...
  196.     OleUninitialize();
Aug 20 '07 #1
2 3432
sicarie
4,677 Expert Mod 4TB
That's a lot of interesting code there.

Did you have a question about it? Is it creating an error? What's the relevance of the code to your dll issue? Have you searched how to make a dll in VC++?
Aug 20 '07 #2
Banfa
9,065 Expert Mod 8TB
Well start by creating a DLL project in MSVC (VC++). This will create the basic file structure and compile and link options you need.

Then add a function with your code in it including the additional function type modifiers require for a DLL function (defined in the symbol DLL_EXPORT I believe).
Aug 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ariant | last post by:
Hi - I'm trying to query my database to find the min, max and average times (in seconds, or minutes, or something) between two timestamps. I've tried using: Select avg(timestamp1 -...
4
by: soni29 | last post by:
hi, i need some help with a query, also to find out if this is even possible with sql. currently i have a table with the following data: CustomerNumber CustomerBranch 123 NULL 123 1...
2
by: Anonymous | last post by:
I'm trying to port code from VC.net to VC.net 2003. Here's a typical piece of code that's often used: template<class T> class PseudoContainer { typedef T::iterator iterator; // this line will...
28
by: Jed | last post by:
Hello to all! I have a couple of projects I intend starting on, and was wondering if someone here could make a suggestion for a good compiler and development environment. My goals are as...
11
by: Tatu Portin | last post by:
Have this kind of struct: typedef struct { char **user_comments; /* ... */ } vorbis_comment; /* prototype */ char * read_vorbis_string ( FILE *sc);
4
by: Anthony Gallagher | last post by:
I have a bunch of libraries compiled using VC++ 6.0, and I am trying to recompile one of our projects using VC++ .NET. I get all kind of linker errors (specially in STL calls). How do I get rid of...
8
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I...
5
by: ashish.sadanandan | last post by:
Hi, Can someone please tell me where I can find those two libraries for Visual C++ 2005 Express Edition compiler? Thanks in advance, Ashish.
0
by: rsadalarasu | last post by:
Hi Everybody, I m very new to Db2. I tried compiling a stored procedure in DB2 Development Center. Build failed with error message like nmake command is unavailable..(something like that). I...
7
by: Norman Diamond | last post by:
A project depends on VC runtime from Visual Studio 2005 SP1, and DotNet Framework 2. Options are set in the setup project properties, so if these two dependencies are not already installed then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.