Powershell cannot use COM object when registration-free COM is used - c++

I am trying to use COM object in regitration-free fashion in powershell. My component is x86 and poweshell_ise.exe is x86 also.
To do this I have created manifest for dll-based com server:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity name="ComComponent" processorArchitecture="X86" type="win32" version="1.0.0.0"></assemblyIdentity>
<file name="ComComponent.dll" hashalg="SHA1">
<comClass clsid="{<CLASS_CLSID>}" tlbid="{<TLB_CLSID>}" progid="ComComponent.ComComponent" description="ComComponent Class"»
<typelib tlbid="{<TLB_CLSID>}" version="1.0" resourceid="2" helpdir="" flags="HASDISKIMAGE"></typelib>
</file>
</assembly>
And manifest for the powershell script:
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="PSScript" type="win32" />
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="ComComponent" version="1.0.0.0"
processorArchitecture="x86" />
</dependentAssembly>
</dependency>
</assembly>
In powershell I am using it in the following way:
$actctx = New-Object -COM Microsoft.Windows.ActCTX
$actctx.Manifest = "<path to manifest>"
$obj= $actctx.CreateObject("ComComponent.ComComponent")
$obj.ComMethod()
After that I am getting the following error:
Method invocation failed because [System.__ComObject] does not contain a method named 'ComMethod'.
I can see that ComComponent.dll is loaded into powershell_ise.exe in Process Explorer. Also I can see that powershell for some reason is trying to read HKCR\TypeLib\{<TLB_CLSID>} registry key.
The same functionality is working in powershell with registred COM. I have tried to put type library into separate file with the same result.
What can be the problem?
Thank you

I would try the following approach:
$myDll = Add-Type –memberDefinition #”
[DllImport("ComComponent.dll")]
public static extern bool myFunction(<parameters>);
“# -name "myDll" -namespace Win32Functions –passThru
$myDll::myFunction(<Parameters>) | Out-Null

Related

Stackdriver Logging | Missing TraceId and SpanId

I am trying to integrate SpringBootApplication(microservice) with StackdriverLogging by using spring-cloud-gcp-starter-logging. I am able to see the logs in GCP but in the logs traceId and SpanId is missing.For this I tried to use Spring-cloud-sleuth also, but as I am using apache kafka in my microservice sleuth is not working properly.
Can anyone help me how Can I add traceId and SpanId information in logs??
POM.xml Configuration :
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-logging</artifactId>
</dependency>
logback.xml :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/cloud/gcp/autoconfigure/logging/logback-json-appender.xml" />
<appender name="CONSOLE_JSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.springframework.cloud.gcp.logging.StackdriverJsonLayout">
<includeTraceId>true</includeTraceId>
<includeSpanId>true</includeSpanId>
<includeThreadName>false</includeThreadName>
</layout>
</encoder>
</appender>
<logger name="org.apache.kafka" level="warn">
<appender-ref ref="CONSOLE_JSON" />
</logger>
<root level="INFO">
<appender-ref ref="CONSOLE_JSON" />
</root>
</configuration>
By default, Sleuth doesn’t send the trace data for every single request. You probably don’t want to trace every single request either. The trace sampling rate can be adjusted by configuring the spring.sleuth.sampler.percentage property. For more details please refer to "Spring Boot and Spring Cloud Sleuth" in this link and have a look to this video.

Unable to add new tags in xml using sed in linux shell [duplicate]

This question already has an answer here:
sed fails with "unknown option to `s'" error [closed]
(1 answer)
Closed 8 years ago.
I am trying to add an xml element in my "pom.xml" file at a particular place, i have tried as the answer mentioned in the following question. But still it is not working..
I do not understand REGEX , so i am having trouble figuring out the problem.
I have to add following xml element between the "properties" and "dependencies" tag.
<distributionManagement>
<repository>
<id>deployment</id>
<name>Internal Releases</name>
<url>http://your.server.com:8081/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
"pom.xml (Before)"
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Component</artifactId>
<version>1.0.0</version>
<packaging>carbon/application</packaging>
<properties>
....
</properties>
<dependencies>
<dependency>
<groupId>com.example.proxy-service</groupId>
<artifactId>Handler</artifactId>
<version>1.0.0</version>
<type>xml</type>
</dependency>
</dependencies>
</project>
pom.xml(After)
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Component</artifactId>
<version>1.0.0</version>
<packaging>carbon/application</packaging>
<properties>
....
</properties>
<distributionManagement>
<repository>
<id>deployment</id>
<name>Internal Releases</name>
<url>http://your.server.com:8081/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>com.example.proxy-service</groupId>
<artifactId>Handler</artifactId>
<version>1.0.0</version>
<type>xml</type>
</dependency>
</dependencies>
</project>
Shell Script:
#!/bin/sh
# First Script
CONTENT="<distributionManagement>\n<repository>\n<id>deployment</id>\n</repository>\n</distributionManagement>"
echo "Start"
C=$(echo $CONTENT | sed 's/\//\\\//g')
sed "/<\/project>/ s/.*/${C}\n&/" *pom.xml*
echo "finish"
Error i am getting:
sed: -e expression #1, char 43: unterminated `s' command
Please help me that if i am following the right command or approach. If there is another command that will do the job but it should be supported both in "Ubuntu" and "Redhat".
I would suggest
#!/bin/bash
CONTENT=" <distributionManagement>
<repository>
<id>deployment</id>
</repository>
</distributionManagement>"
awk -v content="$CONTENT" '{ print $0 } /<\/properties>/ { print content }' pom.xml
This instructs awk to print all lines, and additionally print content (here set to "$CONTENT") if the current line matches </properties>. Generally, I find that if you're tempted to substitute shell variables into sed commands, it's worth considering awk instead. Others will probably disagree.

Slowcheetah app.config pass parameters to transform file

I have following transform file app.Release.config to transform my app.config using SlowCheetah. How do I pass the BUILD_NUMBER from TeamCity so that the transform file replaces a particular xml elements value.
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MyApp.Data.Model" publicKeyToken="866d4a0fa0599fe0" culture="neutral" />
<bindingRedirect name="MyApp.Data.Model.BR" oldVersion="0.0.0.0-$(BUILD_NUMBER)" newVersion="$(BUILD_NUMBER)" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</dependentAssembly>
</assemblyBinding>
If I hard code the value then SlowCheetah does the transformation. But, I don't know how to pass in the build_number as a argument so that for each build I can replace the correct version.
I could not find a way to pass parameters to slowcheetah transform files. I'm using a XmlPoke Task to modify the contents of app.config.
My answer for this can be found at this link

MakeCat failed in Windows 8

I´m having troubles creating a catalog with MakeCat in Windows 8.
After calling with verbose, MakeCat shows the next error:
Failed: CryptCATCDFOpen. Last Error: 0x00000003
If I do it with Windows 7 over the same file, I don't have troubles.
The Catalog Definition File has this content:
[CatalogHeader]
Name=Digi.dll.cat
ResultDir=C:\Users\JoséÁngel\Documents\Visual Studio 2010\Projects\project
[CatalogFiles]
<HASH>Digi.dll.manifest=Digi.dll.manifest
Digi.dll.manifest=Digi.dll.manifest
And the manifest of the dll has this content:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity name="Digi" processorArchitecture="x86" publicKeyToken="82292917b7a6e156" type="win32" version="10.0.0.217"></assemblyIdentity>
<dependency optional="yes">
<dependentAssembly>
<assemblyIdentity type="win32" name="Digi.Resources" version="10.0.0.217" processorArchitecture="x86" publicKeyToken="82292917b7a6e156" language="*"></assemblyIdentity>
</dependentAssembly>
</dependency>
<file name="Digi.dll" hashalg="SHA1" hash="69447737c3bfaf30c611c1755bcfd0f31fbb4557">
<asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform>
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod>
<dsig:DigestValue>GLP5Lao75uVf0ITDkD3b+yN/U8I=</dsig:DigestValue>
</asmv2:hash>
</file>
</assembly>
Solved,
The path of the result directory in the catalog definition file is too large.
Changing everything to a sorter path works correctly.

How to natively add an image to a button in C++ WinAPI (without MFC)?

Okay, I want to add an image to a button ALONG WITH TEXT without making the button in my RC file. Is this even possible, or do I NEED to use an RC file to make the button in able to put an image in it? My image is #defined in "resource.h" and the image is declared in "resources.rc". Both "main.cpp" and "resources.rc" include the "resource.h" header. I really don't want to make a button using resources, but if it
s the only way to make a button with an image AND text, then I'll do it. All I need to know is how to put an image into a button in WinAPI.
UPDATE:
Add manifest file to your application, manifest file should be named YourApp.exe.manifest
Add this into your manifest file(more on manifest file here http://msdn.microsoft.com/en-us/library/bb773175%28VS.85%29.aspx):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="*"
name="CompanyName.ProductName.YourApplication"
type="win32"
/>
<description>Your application description here.</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
Link your application with ComCtl32.lib
Add the manifest to your application resource file CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "YourApp.exe.manifest"
Call InitCommonControls() at the beginning of WinMain
END UPDATE
example code for button creation(IMAGE + TEXT), memory leak prone because of LoadBitmap:
HWND hwnd_button = CreateWindowEx(
0,
"BUTTON", //ascii
"Button text",
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
10,
145,
50,
50,
hwnd_parent,
NULL,
//GetModuleHandle(NULL)
(HINSTANCE)GetWindowLong(hwnd_parent, GWL_HINSTANCE),
NULL);
SendMessage((HWND) m_hWndButton,
(UINT) BM_SETIMAGE,
(WPARAM) IMAGE_BITMAP,
(LPARAM) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1)));