Results 1 to 5 of 5

Thread: So - tell me a little bit about this C++ code I'm starting to write

  1. #1
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 04
    Location
    CT
    Posts
    14,427

    So - tell me a little bit about this C++ code I'm starting to write

    I've been creating C++ functions (unmanaged) to work with strings - and calling them from VB.Net apps (managed code).

    I believe I can do file I/O from C++ as well - I could potentially write a complete C++ app to open a file and search the text of it.

    And if I wanted to output three other files with sorted and arranged text I could do so in C++ as well (doing that with FILEWRITER's in VB.Net now).

    At any rate - could I do this? Would I want to do this?

    Would that mean my .EXE would have NO DEPENDENCIES at all?

    How does a C++ executable work in that regard?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 07
    Location
    0xDEADBEEF
    Posts
    2,419

    Re: So - tell me a little bit about this C++ code I'm starting to write

    What are you using to compile?

    If you are using visual studio you will by default be dependent on the runtime library for whatever version of VS you are using. Some googling has suggested that settings allow you to link to this statically and so lose this dependency.
    W o t . S i g

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 04
    Location
    CT
    Posts
    14,427

    Re: So - tell me a little bit about this C++ code I'm starting to write

    I am using VS 2010 to edit this C++ stuff - in a solution with 5 other VB.Net projects - so I guess VS is doing the compiling. What does the RTL give me - what types of functions?

    Code is looking like this so far - I have had lots of #include's going while trying various things out - but I'm down to just the one now.

    Code:
    // StringLibrary.cpp : Defines the exported functions for the DLL application.
    //
    
    #include "stdafx.h"
    //#include <iostream>
    //#include <vector>
    //#include <string>
    //#include <cmath>
    //#include <algorithm>
    
    //using namespace std;
    
    //typedef std::vector<std::string> StringArray;
    
    extern "C"
    {
    	bool isValue(char *strLocation, const char *checkValue) {
    		int lenLocation = strlen(strLocation);
    		int lenValue = strlen(checkValue);
    		int i = 0;
    		if (lenLocation != lenValue) {return false;}
    		for(i = 0; i <= lenLocation; i++)
    		{
    			if (strLocation[i] != checkValue[i]) {return false;}			
    		}
    		return true;
    	}
    
    	int mxstrcmp(char *strSearch, int x1s, int x1e, int x2s, int x2e) {
    		int rsc = 0;
    		
    		int x1l = x1e - x1s + 1;
    		int x2l = x2e - x2s + 1;
    		int cc = 0;
    
    		do {
    			if ((x1s + cc <= x1e) && (x2s + cc <= x2e)) {
    				if (strSearch[x1s + cc] < strSearch[x2s + cc]){
    					rsc = -1;
    				} else if (strSearch[x1s + cc] > strSearch[x2s + cc]) {
    					rsc = 1;
    				}
    			} else {
    				if (x2l > x1l) {
    					rsc = -1;
    				} else if (x2l < x1l) {
    					rsc = 1;
    				}
    			}
    			cc++;
    		} while (rsc == 0 && cc <= x1l && cc <= x2l);
    		return rsc;
    	}
    .
    .
    .

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 07
    Location
    0xDEADBEEF
    Posts
    2,419

    Re: So - tell me a little bit about this C++ code I'm starting to write

    What does the RTL give you? In truth I don't know exactly, but MSDN has quite a lot of information

    This blog describes how to use VS to link to the runtime statically and discusses the pros and cons of this.

    Generally speaking it seems that dynamically linking to the runtime is best for most situations. The code you show is pretty basic so it might well be a good contender for static linking. That said the runtime is pretty small so in the grand scheme of things, given that your project is already dependent on the enormous net framework, I don't see how linking statically gives you any real advantage.
    Last edited by Milk; Aug 5th, 2012 at 04:46 PM. Reason: updated MSDN link to refer to the current VS
    W o t . S i g

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 04
    Location
    CT
    Posts
    14,427

    Re: So - tell me a little bit about this C++ code I'm starting to write

    Thanks - great links!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •