Wednesday, July 2, 2008

VC++ .Net 2005, some tips

  1. For accessing the “range” value in the word document the syntax is different for C# and VC++. To access the range value for the paragraph object the following is to be done
    VC++ :
    Word::Paragraph ^oPara1;
    oPara1 = oDoc->Content->Paragraphs->Add(oMissing);
    wrdRng = oDoc->Bookmarks->default::get(oEndOfDoc)->Range;
    oPara1->default->default= "Heading 2";
    C# :
    Word.Paragraph oPara1;
    oPara1 = oDoc.Content.Paragraphs.Add(oMissing);
    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
    oPara1.Text = "Heading 2";
  2. For preparing the application for the client having a different language than English the following code has to be added for the operations to be performed in the Excel sheets:

    System::Globalization::CultureInfo ^ originalCulture = System::Threading::Thread::CurrentThread->CurrentCulture;
    System::Threading::Thread::CurrentThread->CurrentCulture = gcnew System::Globalization::CultureInfo("en-US");
    …..
    ….
    The application code
    …..
    …..
    System::Threading::Thread::CurrentThread->CurrentCulture = originalCulture;

    This is required as the language of the OS for the client system maybe other than English. This changes the display format in the client machines and the default behavior of the keyboard inputs. The above code helps to change the behavior of Excel according to the English language.
    Also the problem may occur when the application uses the values being displayed in the UI at the client side. As the values (e.g. Date) may have a different format in the client machine using the value directly for some calculations (e.g. Querying the database) may give a run-time error.
  3. For calling a function in the Office applications (like MS Word) there are two methods
    Late binding:
    findObj->GetType()->InvokeMember("Execute", BindingFlags::InvokeMethod, nullptr, findObj, args7);
    This function invokes the function “Execute”. So at the run-time the function to be invoked is understood.
    Early binding:
    findObj->Execute((Object ^) sFindText,oMissing,oMissing, oMissing,oMissing, oMissing,oMissing,oMissing,oMissing,(Object ^)sReplaceText,oMissing, oMissing,oMissing,oMissing, oMissing);
    One of these two methods can be used for calling a function.
  4. Use “Überschrift” instead of “Heading” as the font name in the word document creation. This is specific to German language.
  5. The code when compiled on the German OS system, may sometimes not work on an English OS system. The solution is to recompile the same on the English OS. This recompiled code will work on both the systems viz. German OS and English OS systems. The piece of code to be checked for the execution inconsistency is the part where threading is undertaken. The code which initializes and starts the thread has to be checked for the possible error.
  6. MS Access uses the format “mm:dd:yyyy” (US format)for the dates in the queries to be executed. We were formatting the query in “dd:mm:yyyy” (German format). The query output differed to what was expected.

No comments:

Post a Comment