473,664 Members | 3,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help in Vc++

1 New Member
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 3438
sicarie
4,677 Recognized Expert Moderator Specialist
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 Recognized Expert Moderator Expert
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
10939
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 - timestamp2) from table; I get an error saying that avg() expects a number, not an interval. Is there a way (in a SQL stmt) to convert timestamps (or their
4
2493
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 123 2 221 NULL 221 5
2
2079
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 change in the next example... };
28
2464
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 follows: 1. Develop the project code on XP.
11
1908
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
2952
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 these errors?? Anthony
8
1828
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 need to build multiple mixed mode dll's used by a consumer application, do I have to implement multiple ManagedWrapper's (each embedded in indiviudal DLL project) and call all of them in my consumer application?
5
11458
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
1397
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 came to know that Db2 8.1 need VC++ to be installed to compile a stored procedure. Now the problem is I dont have VC++ installed in my machine. I need to compile the stored proc desperately. But some how i got the installed version of VC++ from...
7
8443
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 this installer will install them. But what about the situation where VC runtime has already been installed? In fact it's been installed twice. Although the project was built on a Windows XP system with Visual Studio 2005 SP1 and the results were...
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8861
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7375
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2764
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.